البرنامج :


كود:
/*1-Comments
ADC &LCD
PIC16F877A
Oscillator * 4MHz, MCLR Enabled, PWRT Enabled, WDT OFF
*/
//2- LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections
//3- Define Messages and variables
char message1[] = "ADC Value= ";
char *temp = "0000";
unsigned int adc_Value;
//4- main
void main() {
TRISD = 0; // PORTD All Outputs
TRISA = 0b00000001; // PORTA All Outputs, Except RA0
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,message1); // Write message1 in 1st row
Lcd_Out(2,1,"Eng.F.ABDELAZIZ");
while(1) {
adc_value = ADC_Read(0);
temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
temp[1] = (adc_value/100)%10 + 48;
temp[2] = (adc_value/10)%10 + 48;
temp[3] = adc_value%10 + 48;
Lcd_Out(1,11,temp);
Delay_ms(1000);
}
}
التعليق على البرنامج :