Sunday, December 20, 2015

Control your TV from PIC12F1822 microcontroller


Using PIC12F1822 microcontroller we can easily build a remote control. This topic shows how to build a TV remote control, this TV uses RC-5 protocol which means we have to make an RC5 IR remote control protocol encoder.
Useful topics:

RC5 IR remote control protocol decoder with PIC12F1822

Infrared (IR) remote control system based on PIC12F1822

TV remote control circuit schematic diagram:

tv control remote control circuit pic microcontroller pic12f1822 projects mikroc code

Internal oscillator is used (32MHz) and MCLR pin function is disabled.
TV remote control mikroC code:

 // TV remote control using PIC12F1822
 // RC-5 protocol used
 // Written by: BENCHEROUDA Okba
 // electronnote@gmail.com
 // http://elecnote.blogspot.com/
 // Internal oscillator used @ 32MHz
 // Use at your own risk

 bit  toggle;
 unsigned short i;
 void send_signal(unsigned short address, unsigned short command){
   // Start bit
   PWM1_Start();
   delay_us(889);
   PWM1_Stop();
   delay_us(889);
   PWM1_Start();
   delay_us(889);
   PWM1_Stop();
   // Toggle bit
   toggle = ~toggle;
   if(toggle){
     delay_us(889);
     PWM1_Start();
     delay_us(889);
     }
   else {
     PWM1_Start();
     delay_us(889);
     PWM1_Stop();
     delay_us(889);
     }
   // Address
   for(i = 0x10; i > 0; i = i >> 1){
     if( address & i ){
       PWM1_Stop();
       delay_us(889);
       PWM1_Start();
       delay_us(889);}
     else {
       PWM1_Start();
       delay_us(889);
       PWM1_Stop();
       delay_us(889);}}
   // Command
   for (i = 0x20; i > 0; i = i >> 1){
     if ( command & i ){
       PWM1_Stop();
       delay_us(889);
       PWM1_Start();
       delay_us(889);}
     else {
       PWM1_Start();
       delay_us(889);
       PWM1_Stop();
       delay_us(889);
       }
     }
   PWM1_Stop();
   }
 void main() {
   OSCCON = 0xF0; // Internal oscillator 8MHz and PLL enabled (gives 32MHz)
   ANSELA = 0;    // All I/O pins are configured as digital
   ADCON0 = 0;    // Disable ADC module
   PORTA = 0;     // Initial value of port A bits
   TRISA = 0x1F;
   WPUA = 0x1F;      // Enable pull-up resistors
   OPTION_REG = 0;
   APFCON = 1;         // PWM output on RA5
   PWM1_Init(36000);   // PWM module initialization (36KHz)
   PWM1_Set_Duty(127); // Set PWM duty cycle
   while(1){
     if(Button(&PORTA, 0, 100, 0)){     // Volume up
       send_signal(0, 16);
       delay_ms(100);
       }
     if(Button(&PORTA, 1, 100, 0)){    // Volume down
       send_signal(0, 17);
       delay_ms(100);
       }
     if(Button(&PORTA, 2, 100, 0)){    // Program up
       send_signal(0, 32);
       delay_ms(100);
       }
     if(Button(&PORTA, 3, 100, 0)){   // Program down
       send_signal(0, 33);
       delay_ms(100);
       }
     if(Button(&PORTA, 4, 100, 0)){   // Standby
       send_signal(0, 12);
       delay_ms(100);
       }
     }
   }

Project video:
The following video has more descriptions about this project.