|
|
View previous topic :: View next topic |
Author |
Message |
sirisopa
Joined: 25 Mar 2008 Posts: 2
|
TLC2543 Help me please !! ( TLC2543 Hi-tech C to CCSC Code) |
Posted: Wed Apr 02, 2008 3:43 am |
|
|
#include <pic.h>
/*
Freely distributable in this original form.
(c) Feb 2000 Shane Tolmie
(c) KeyGhost, now you can record keystrokes on PC with tiny device
Any questions or comments? [email protected]
Updates to FAQ available from http://www.keyghost.com/htpic
Routines to setup and use the TLC2543 serial 11channel 12bit a/d converter.
For Hi-Tech C v7.85, on a generic PIC micro.
Tested with PIC16F84, PIC12CE674, and PIC16F876 all @ 4Mhz, should work at 16Mhz
Code status: tested and works beautifully.
- the current channel is set by the previous channel supplied
- initially two calls must be made to ad_setgetchannel(), or use slower ad_getchannel(x)
Sample C:
ad_setup(); //sets up port directions
garbage=ad_setgetchannel(0); //sets up current channel to zero, garbage returned
data=ad_setgetchannel(1); //data now has channel 0. Channel for next call is 1
data=ad_setgetchannel(2); //data now has channel 1. Channel for next call is 2
alternatively, use the slower, but more intuitive
ad_getchannel(x). //this uses two calls to return data at channel x.
WARNING: these chips are static sensitive - I had two cease to work on me for some reason.
*/
#define io_clk RB0 //clock on port B bit 7
#define io_clk_dir TRISB0 //clock on port B bit 7
#define ad_data_in RB1
#define ad_data_in_dir TRISB1
#define ad_data_out RB2 //data on port A bit 1
#define ad_data_out_dir TRISB2 //data on port A bit 1
#define ad_cs RB3
#define ad_cs_dir TRISB3
#define port_out 0
#define port_in 1
//call this once to set it up
void ad_setup()
{
//these in/outs are a bit confusing - its from the TLC2543's perspective
ad_data_in_dir = port_out;
ad_data_out_dir = port_in;
io_clk_dir = port_out;
ad_cs_dir = port_out;
}
unsigned int ad_setgetchannel(unsigned char channel)
{
signed char i;
unsigned int data = 0x0;
unsigned int ch_config;
ch_config = channel<<8;
io_clk = 0; //ensure clock is low
ad_cs = 0;
for(i=11; i>=0; i--)
{
ad_data_in = ((ch_config>>i) & 0x01); //bit to send
data <<= 1; //read the next bit
data |= ad_data_out;
io_clk = 1; //ensure clock is high
io_clk = 0; //ensure clock is low
}
ad_cs = 1;
return data;
}
//recommended routine to call, its only a little slower
unsigned int ad_getchannel(unsigned char channel)
{
unsigned int dummy;
// call it twice to get and set the channel
dummy=ad_setgetchannel(channel); //get garbage channel, but set next one
dummy=ad_setgetchannel(channel); //get current channel
return dummy;
} |
|
|
sirisopa
Joined: 25 Mar 2008 Posts: 2
|
|
Posted: Wed Apr 02, 2008 3:45 am |
|
|
Code: |
#include <pic.h>
/*
Freely distributable in this original form.
(c) Feb 2000 Shane Tolmie
(c) KeyGhost, now you can record keystrokes on PC with tiny device
Any questions or comments? [email protected]
Updates to FAQ available from http://www.keyghost.com/htpic
Routines to setup and use the TLC2543 serial 11channel 12bit a/d converter.
For Hi-Tech C v7.85, on a generic PIC micro.
Tested with PIC16F84, PIC12CE674, and PIC16F876 all @ 4Mhz, should work at 16Mhz
Code status: tested and works beautifully.
- the current channel is set by the previous channel supplied
- initially two calls must be made to ad_setgetchannel(), or use slower ad_getchannel(x)
Sample C:
ad_setup(); //sets up port directions
garbage=ad_setgetchannel(0); //sets up current channel to zero, garbage returned
data=ad_setgetchannel(1); //data now has channel 0. Channel for next call is 1
data=ad_setgetchannel(2); //data now has channel 1. Channel for next call is 2
alternatively, use the slower, but more intuitive
ad_getchannel(x). //this uses two calls to return data at channel x.
WARNING: these chips are static sensitive - I had two cease to work on me for some reason.
*/
#define io_clk RB0 //clock on port B bit 7
#define io_clk_dir TRISB0 //clock on port B bit 7
#define ad_data_in RB1
#define ad_data_in_dir TRISB1
#define ad_data_out RB2 //data on port A bit 1
#define ad_data_out_dir TRISB2 //data on port A bit 1
#define ad_cs RB3
#define ad_cs_dir TRISB3
#define port_out 0
#define port_in 1
//call this once to set it up
void ad_setup()
{
//these in/outs are a bit confusing - its from the TLC2543's perspective
ad_data_in_dir = port_out;
ad_data_out_dir = port_in;
io_clk_dir = port_out;
ad_cs_dir = port_out;
}
unsigned int ad_setgetchannel(unsigned char channel)
{
signed char i;
unsigned int data = 0x0;
unsigned int ch_config;
ch_config = channel<<8;
io_clk = 0; //ensure clock is low
ad_cs = 0;
for(i=11; i>=0; i--)
{
ad_data_in = ((ch_config>>i) & 0x01); //bit to send
data <<= 1; //read the next bit
data |= ad_data_out;
io_clk = 1; //ensure clock is high
io_clk = 0; //ensure clock is low
}
ad_cs = 1;
return data;
}
//recommended routine to call, its only a little slower
unsigned int ad_getchannel(unsigned char channel)
{
unsigned int dummy;
// call it twice to get and set the channel
dummy=ad_setgetchannel(channel); //get garbage channel, but set next one
dummy=ad_setgetchannel(channel); //get current channel
return dummy;
}
|
best regard
wichan |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|