سلام من یک پروژه خواندن adc کار میکنم که سورس اون رو هم گذاشتم ، که روی یک پورت وهمچنین روی lcd میخواهم نمایش بده . روی پورت مشکلی نداره ولی روی lcd بصورت اسکی نمایش داده میشه ، اگه ممکنه راهنمایی کنید عدد رو چطوری روی lcd نمایش بدم .
سورس برنامه با Mikro C هست.
سورس برنامه با Mikro C هست.
long tmp;
// Lcd pinout settings
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D4 at RD0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D7_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD0_bit;
void main() {
ANSEL = 0x04; // Configure AN2 pin as analog
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
Lcd_Init();
ADC_Init(); // Initialize ADC module with default settings
TRISA = 0xFF; // PORTA is input
TRISC = 0; // PORTC is output
TRISB = 0; // PORTB is output
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
do {
tmp = ADC_Read(2); // Get 10-bit results of AD conversion
Lcd_Out(1,2,tmp); // Write text in first row
PORTB = tmp; // Send lower 8 bits to PORTB
PORTC = tmp >> 8; // Send 2 most significant bits to RC1, RC0
} while(1);
}
دیدگاه