Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SIRC decoding PIC16F676 in place of PIC18F2620

Status
Not open for further replies.

sahu

Advanced Member level 2
Joined
Oct 9, 2009
Messages
516
Helped
68
Reputation
130
Reaction score
62
Trophy points
1,308
Location
Uttar pradesh (INDIA)
Activity points
3,876
help me this code ... for conversion
i am using PIC16F676 in place of PIC18F2620

Code:
#define IR TRISA.F3
#define LED1 PORTC.F0
#define LED2 PORTC.F1
#define LED3 PORTC.F2
#define LED4 PORTC.F3
#define LED5 PORTC.F4
#define LED6 PORTC.F5
#define BZR PORTA.F0
#define LED7 PORTA.F1
#define LED8 PORTA.F2

unsigned counter = 0;
unsigned input_data, bit_count;

enum {
 Idle,
 Start_bit,
 Capture_bit
};

char Current_state = Idle;
char got_data = 0;
char Command_code, Device_code;

void interrupt(){
 if(INTCON.INTF){
 switch (Current_state){
 case Idle:
[COLOR=#ff0000]INTCON2.INTEDG0[/COLOR] = 1; //interrupt on rising edge.
 counter = 0;
 Current_state = Start_bit;
 break;
 //found the rising edge, check lenght for 2.4ms
 case Start_bit:
 //correct signal, move on to next state
 if(counter == 4) {
 counter = 0;
 bit_count = 0;
 input_data = 0;
 Current_state = Capture_bit;
 } else {
 //fault signal, reset to Idle
 Current_state = Idle;
 }
 break;
 case Capture_bit:
 //check plus length for 0 or 1
 if(counter == 2){
 input_data >>= 1; // add 0 to received data
 bit_count++;
 }else {
 if(counter == 3){
 input_data >>= 1;
 input_data |= 0x8000; //add 1 to received data
 bit_count++;
 } else {
 //error occurs, reset to Idle state
[COLOR=#ff0000]INTCON2.INTEDG0[/COLOR] = 0; //interrupt on falling edge.
 Current_state = Idle;
 }
 }
 //compleat 12 bit
 if(bit_count >= 12){
 got_data = 1;
 input_data >>= 4;
[COLOR=#ff0000]INTCON2.INTEDG0[/COLOR] = 0; //interrupt on falling edge.
 Current_state = Idle;
 }
 counter = 0;
 break;
 default: Current_state = Idle;
 }
 INTCON.INTF = 0; //clear interrupt flag.
 }
 if(PIR1.TMR1IF){
 counter++;
 if(counter > 5) {
 Current_state = Idle;
 counter = 0;
[COLOR=#ff0000]INTCON2.INTEDG0[/COLOR] = 0; //interrupt on falling edge.
 }
 PIR1.TMR1IF = 0; //clear interrupt flag
 }
}

//******************************************************************************
// MAIN MAIN MAIN MAIN
//******************************************************************************
void main() {
 TRISC = 0; //portc is output
 TRISA = 8; //portA is output
//******************************************************************************
// RB0 interrupt set up
//******************************************************************************
 INTCON.[COLOR=#ff0000]INT0IE[/COLOR] = 1; //enable RB0 interrupt.
[COLOR=#ff0000]INTCON2.INTEDG0[/COLOR] = 0; //interrupt on falling edge.
 IR = 1; //RB0 = input.
 ADCON1 = 0x0F; //all digital I/O
//******************************************************************************
// Timer2 interrupt set up, interrupt every 600us
//******************************************************************************
[COLOR=#ff0000]T2CON[/COLOR] = 2; //timer off, prescaler 1:16
[COLOR=#ff0000]PR2[/COLOR] = 149; //preload timer2 comparator value.
[COLOR=#ff0000]TMR2[/COLOR] = 0; //reset value timer2
 PIR1.TMR1IF = 0; //clear interrupt flag.
 PIE1.TMR1IE = 1; //enable timer2 interrupt.
[COLOR=#ff0000]IPR1.TMR1IP[/COLOR] = 1; //timer2 interrupt high priority
//******************************************************************************
// Global interrupt enable
//******************************************************************************
 INTCON.PEIE = 1; //enable interrupt
 INTCON.GIE = 1; //enable global interrupt

[COLOR=#ff0000]T2CON.TMR2ON[/COLOR] = 1; //timer2 is on
 while(1){
 if(got_data){
 Command_code = input_data & 0x7F;
 Device_code = input_data >> 7;
 got_data = 0;
 if(Device_code == 1){
 switch (Command_code){
 case 1: LED1 = ~LED1; break;
 case 2: LED2 = ~LED2; break;
 case 3: LED3 = ~LED3; break;
 case 4: LED4 = ~LED4; break;
 case 5: LED5 = ~LED5; break;
 case 6: LED6 = ~LED6; break;
 case 7: LED7 = ~LED7; break;
 case 8: LED8 = ~LED7; break;
 }
 PIE1.[COLOR=#ff0000]TMR2IE[/COLOR] = 0; //disable timer2 interrupt.
 Delay_ms(100);
[COLOR=#ff0000]TMR2[/COLOR] = 0; //reset value timer2
 PIE1.[COLOR=#ff0000]TMR2IE[/COLOR] = 1; //enable timer2 interrupt.
 }
 }
 }

}

found error .
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top