Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top