![]() |
![]() |
#1 |
Nhập môn đệ tử
Tham gia ngày: Mar 2011
Bài gửi: 3
: |
hiển thị giá trị ADC lên LCD ?
chào các bạn! các bạn ơi, làm ơn xem giúp hộ mình đoạn code này xem nó sai ở đâu mà không hiểu sao nó không hiển thị giá trị trên LCD cũng như trên LED đúng? cám ơn các bạn nhiểu!
ý của mình là nếu điện áp lớn nhất vào A0 thì LCD hiện 255 và tất cả các LED đểu sáng...tương tự các giá trị với các mức điện áp khác nhau vào A0. giúp mình nhé! #include<16f877A.h> #fuses HS,NOWDT,NOPROTECT,NOLVP #device 16f877A*=16 ADC=8 #use delay(clock=20M) #define LCD_RS PIN_D0 //#define LCD_RW PIN_A1 #define LCD_EN PIN_D2 #define LCD_D4 PIN_D4 #define LCD_D5 PIN_D5 #define LCD_D6 PIN_D6 #define LCD_D7 PIN_D7 // misc display defines- #define Line_1 0x80 #define Line_2 0xC0 #define Clear_Scr 0x01 // prototype statements #separate void LCD_Init ( void );// ham khoi tao LCD #separate void LCD_SetPosition ( unsigned int cX );//Thiet lap vi tri con tro #separate void LCD_PutChar ( unsigned int cX );// Ham viet1kitu/1chuoi len LCD #separate void LCD_PutCmd ( unsigned int cX) ;// Ham gui lenh len LCD #separate void LCD_PulseEnable ( void );// Xung kich hoat #separate void LCD_SetData ( unsigned int cX );// Dat du lieu len chan Data // D/n Cong #use standard_io ( B ) #use standard_io (A) //khoi tao LCD********************************************** #separate void LCD_Init ( void ) { LCD_SetData ( 0x00 ); delay_ms(200); output_low ( LCD_RS );// che do gui lenh LCD_SetData ( 0x03 ); LCD_PulseEnable(); LCD_PulseEnable(); LCD_PulseEnable(); LCD_SetData ( 0x02 ); LCD_PulseEnable(); LCD_PutCmd ( 0x2C ); LCD_PutCmd ( 0b00001100); LCD_PutCmd ( 0x06 ); LCD_PutCmd ( 0x01 ); } #separate void LCD_SetPosition ( unsigned int cX ) { /* this subroutine works specifically for 4-bit Port A */ LCD_SetData ( swap ( cX ) | 0x08 ); LCD_PulseEnable(); LCD_SetData ( swap ( cX ) ); LCD_PulseEnable(); } #separate void LCD_PutChar ( unsigned int cX ) { /* this subroutine works specifically for 4-bit Port A */ output_high ( LCD_RS ); LCD_PutCmd( cX ); output_low ( LCD_RS ); } #separate void LCD_PutCmd ( unsigned int cX ) { /* this subroutine works specifically for 4-bit Port A */ LCD_SetData ( swap ( cX ) ); /* send high nibble */ LCD_PulseEnable(); LCD_SetData ( swap ( cX ) ); /* send low nibble */ LCD_PulseEnable(); } #separate void LCD_PulseEnable ( void ) { output_high ( LCD_EN ); delay_us ( 3 ); // was 10 output_low ( LCD_EN ); delay_us ( 500 ); // was 5 } #separate void LCD_SetData ( unsigned int cX ) { output_bit ( LCD_D4, cX & 0x01 ); output_bit ( LCD_D5, cX & 0x02 ); output_bit ( LCD_D6, cX & 0x04 ); output_bit ( LCD_D7, cX & 0x08 ); } main() { int8 adc; int8 truc,donvi,tram; set_tris_b(0); set_tris_d(0); setup_adc(adc_clock_internal); setup_adc_ports(AN0); set_adc_channel(0); delay_us(10); LCD_Init(); LCD_PulseEnable(); while(1) { adc=read_adc(); output_B(adc); LCD_SetPosition(0); tram =adc/100; adc =adc%100; truc=adc/10; donvi=adc%10; LCD_PutChar(tram+0x30); LCD_PutChar(truc+0x30); LCD_PutChar(donvi+0x30); } } |
![]() |
![]() |
![]() |
#2 |
Nhập môn đệ tử
Tham gia ngày: Mar 2011
Bài gửi: 3
: |
không ai giúp mình ah?
![]() |
![]() |
![]() |
![]() |
#3 |
Đệ tử 7 túi
Tham gia ngày: May 2005
Bài gửi: 258
: |
tham khảo code sau:
Code:
#include<16f877A.h> #fuses HS,NOWDT,NOPROTECT,NOLVP #device 16f877A*=16 ADC=8 #use delay(clock=20M) #include <lcd.c> main() { int8 adc; int8 truc,donvi,tram; set_tris_b(0); set_tris_d(0); setup_adc(adc_clock_internal); setup_adc_ports(AN0); set_adc_channel(0); delay_us(10); LCD_Init(); lcd_gotoxy(1,1); Printf(LCD_putc,"gia tri ADC la:"); while(1) { adc=read_adc(); output_B(adc); tram =adc/100; adc =adc%100; truc=adc/10; donvi=adc%10; lcd_gotoxy(1,2); LCD_Putc(tram+0x30); LCD_Putc(truc+0x30); LCD_Putc(donvi+0x30); } }
__________________
viết chương trình cho vdk chạy ổn định là cả một vấn đề. thay đổi nội dung bởi: tdm, 20-03-2011 lúc 06:24 PM. |
![]() |
![]() |
![]() |
#4 |
Nhập môn đệ tử
Tham gia ngày: Mar 2011
Bài gửi: 3
: |
mình cám ơn bạn rất rất nhiều nhé, mình làm được rồi!
![]() |
![]() |
![]() |
![]() |
#5 |
Đệ tử 2 túi
Tham gia ngày: Jan 2011
Bài gửi: 36
: |
Ông kia cảm ơn người ta thì nhấn vào nút thanks kìa ????
![]() ![]() thay đổi nội dung bởi: ElecTel, 28-03-2011 lúc 12:28 AM. |
![]() |
![]() |
![]() |
|
|