LDR programming with C

Status
Not open for further replies.

hashoom89

New Member
hi
please i need help to programming microcontroller PIC18f4550
the program must sense LDR sensor
and in this project i used dc motor to control blinds open or closed
please i need your help
 
Here a little sample for your chip to use ADC It should work

Code:
unsigned int temp_res;

void main() {
  ADCON1 = 0b00001110;              // Configure AN0 pin as analog
  ADCON0 = 0d00000001;                 // Configure other AN pins as digital I/O
   
  TRISA  = 0xFF;              // PORTA is input
  TRISC  = 0;                 // PORTC is output
  TRISD  = 0;                 // PORTD is output

  do {
    temp_res = ADC_Read(0);   // Get 10-bit results of AD conversion
    PORTD = temp_res;         // Send lower 8 bits to PORTD
    PORTC = temp_res >> 8;    // Send 2 most significant bits to RC1, RC0
  } while(1);
}
// this code should light up 10 leds 8 of them on portd and the last 2 portc 0,1
 
Last edited:
Good point. Need to go back to grade school and learn to read. I'll remove it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…