??? 08/15/07 01:59 Read: times |
#143295 - LCD code Responding to: ???'s previous message |
Thanks for the explanation on
>> adc_sum >>=4; // /16 => 8 BIT result Now I understand better.I am sorry that I didn't post my display code..I am trying to display a voltage value in my LCD like when I put 3V,my LCD will display 3V...Am I missing something in the code? Here's my code: //----------------------------------------------------------------------------- // Includes //----------------------------------------------------------------------------- #include <c8051F200.h> #include <stdlib.h> //----------------------------------------------------------------------------- // Global CONSTANTS //----------------------------------------------------------------------------- unsigned int q; sbit RS = P2^5; // RS (Register Select) for Port 2.5 sbit RW = P2^6; // RW for Port 2.6 sbit E = P2^7; // Enable for Port 2.7 sbit DB0 = P3^0; //DB = Data bus sbit DB1 = P3^1; sbit DB2 = P3^2; sbit DB3 = P3^3; sbit DB4 = P3^4; sbit DB5 = P3^5; sbit DB6 = P3^6; sbit DB7 = P3^7; //----------------------------------------------------------------------------- // Function PROTOTYPES //----------------------------------------------------------------------------- void config(void); void delay (unsigned int duration); void enable(); void lcdinit (void); void command(unsigned char m); void print(unsigned char k); void hi(); void adcdata(void); //------------------------------------------------------------------------------------ // Generating Delay //------------------------------------------------------------------------------------ void delay (unsigned int duration) { while (duration--!=0); } //------------------------------------------------------------------------------------ // Enable //------------------------------------------------------------------------------------ void enable() { E = 1; delay(150); E = 0; delay(150); } //------------------------------------------------------------------------------------ // Initialize LCD //------------------------------------------------------------------------------------ void lcdinit(void) { E=0; RW=0; RS=0; P3=0x38; // 8bit, 2 lines, default font enable(); P3=0x0C; // on dispaly enable(); P3=0x06; // entry mode, not to shift enable(); P3=0x01; // clear dispay and cursor return enable(); P3=0x02; // cursor return enable(); } //------------------------------------------------------------------------------------ // Command Character to LCD //------------------------------------------------------------------------------------ void command(unsigned char m) { P3 = m; RS = 0; RW = 0; enable(); } //------------------------------------------------------------------------------------ // Print Character to LCD //------------------------------------------------------------------------------------ void print(unsigned char k) { P3 = k; RS = 1; RW = 0; enable(); } void adcdata(void) { unsigned int adc_sum = 0; unsigned int adc_count = 0; for(adc_count = 0;adc_count < 16;adc_count++) { ADCINT = 0; ADBUSY = 1; while(!ADCINT); //conversion complete ? adc_sum += ADC0H; //build an average } adc_sum >>= 4; // /16 => 8 BIT result print(adc_sum); } //----------------------------------------------------------------------------- // MAIN Routine //----------------------------------------------------------------------------- void main() { config(); lcdinit(); //Initialize LCD command(0x80); ADCEN = 1; //enable ADC while(1) //endless loop { delay(500000); adcdata(); delay(500000); } } |
Topic | Author | Date |
ADC Problem | 01/01/70 00:00 | |
Circuit ? | 01/01/70 00:00 | |
Clarify? | 01/01/70 00:00 | |
Crosspost | 01/01/70 00:00 | |
Clarification | 01/01/70 00:00 | |
Still no circuit | 01/01/70 00:00 | |
Power supply | 01/01/70 00:00 | |
What about the adc lowbyte ? | 01/01/70 00:00 | |
Power Supply | 01/01/70 00:00 | |
Power supply | 01/01/70 00:00 | |
Power Supply | 01/01/70 00:00 | |
ADC lowbyte | 01/01/70 00:00 | |
sorry for confusing you but | 01/01/70 00:00 | |
Thanks for the time | 01/01/70 00:00 | |
mmmhhh one more time | 01/01/70 00:00 | |
LCD code | 01/01/70 00:00 | |
No majic | 01/01/70 00:00 | |
delay | 01/01/70 00:00 | |
Writing Timing Loops in C | 01/01/70 00:00 | |
Lucky | 01/01/70 00:00 | |
Very true! | 01/01/70 00:00 | |
Your adc value must be 123. { | 01/01/70 00:00 | |
Power Supply Problem | 01/01/70 00:00 | |
We can not see what you are looking at | 01/01/70 00:00 | |
current limiting power supply? | 01/01/70 00:00 | |
Power Supply | 01/01/70 00:00 | |
Power Supply | 01/01/70 00:00 | |
ADC0804 with 8051 | 01/01/70 00:00 | |
Start a new thread! | 01/01/70 00:00 | |
Sorry Dude!!!![]() | 01/01/70 00:00 |