|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 01, 2007 2:46 pm |
|
|
Try a more simple program:
Code: | #include <16F628A.H>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#use i2c(master, scl=PIN_A2, sda=PIN_A3)
#include <flex_lcd.c>
//-----------------------------------
#define MCP3021_READ_ADDR 0b10011011
int16 read_mcp3021(void)
{
int8 lsb;
int8 msb;
int16 retval;
i2c_start();
i2c_write(MCP3021_READ_ADDR);
msb = i2c_read();
lsb = i2c_read(0);
i2c_stop();
retval = make16(msb, lsb) >> 2;
return(retval);
}
//============================
void main()
{
int16 result;
lcd_init();
while(1)
{
result = read_mcp3021();
printf(lcd_putc, "\f%lx ", result);
delay_ms(500);
}
} |
|
|
|
Doglao
Joined: 26 Mar 2007 Posts: 11
|
|
Posted: Thu Nov 01, 2007 4:06 pm |
|
|
Thanks for all!
it is working now!
I put a 11us delay before read the data, this delay is necessary to make a acquisition time Tacq(1.12usec) plus Conversion Time Tconv(8.96) and this work well, the values changing linearity. the other thing that I know now, is to join msb and lsb with make16() command.
very very very thanks!! _________________ Breaking rocks in the hot sun!
Doglao |
|
|
|
|
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
|