i want to use adc of 16f877a to on led from the begining to the end .... b1-c1
this is my program help will be appreciated
this is my program help will be appreciated
C:
//[cc lang=”C”]
unsigned int adc =0; // Variable to save ADC value
const unsigned short VREF = 5;
int val;
void main() // Start of Main function
{
CMCON = 0x07; // Disable Comparators
ADCON1 = 0x80; // For ADC Module configuration
TRISA = 0xFF; // PORTA is input (ADC Input)
TRISB0_bit = 0x00;
TRISB1_bit = 0x00; // PORTB is output
TRISB2_bit = 0x00;
TRISB3_bit = 0x00;
TRISB4_bit = 0x00;
TRISB5_bit = 0x00;
TRISB6_bit = 0x00;
TRISB7_bit = 0x00;
TRISC0_bit = 0x00; // PORTC is Output
TRISC1_bit = 0x00;
do
{
adc = ADC_Read(1); // Get 10-bit results of AD conversion of channel 1
val =(adc * VREF )/1024;
TRISB0_bit= val =1 ; // Send lower 8 bits to PORTB
TRISC0_bit = val =2; // PORTC is Output
TRISC1_bit =val =3; // Send 2 most significant bits to RC7, RC6
TRISB1_bit =val =4; // PORTB is output
TRISB2_bit = val =5;
TRISB3_bit = val =6;
TRISB4_bit = val =7;
TRISB5_bit = val =8;
TRISB6_bit = val =9;
TRISB7_bit = val =10;
}
while(1);
}
Last edited by a moderator: