IR Switch SIRC Sony protocol PIC16F84A & PIC16F628

General discussion on mikroBasic.
Post Reply
Author
Message
Obak
Posts: 5
Joined: 20 Apr 2015 10:19

IR Switch SIRC Sony protocol PIC16F84A & PIC16F628

#1 Post by Obak » 30 Sep 2015 06:46

Hi, I am using microc pro and creating a project LED on of project using PIC16F84A - Project has build and working successfully with PIC16F84A but I want convert to PIC16F628. But when convert the project project dose no working -
Any body help me what is the problem here-

working project PIC16F84A-
----------------------------------------------------------------------------------------------------------------------
sbit ir_rx at PORTA.B2;

// function prototypes
void get_mark_time(void);


// global variables
unsigned char counter = 0;
unsigned char shadow = 0;
unsigned char bitcount;
unsigned char ir_address;
unsigned char ir_command;
unsigned int mark_time;

void interrupt() {

if (INTCON.T0IF) {
counter++;
INTCON.T0IF = 0;
}
}

void main() {

OPTION_REG = 0x04;
TRISA = 0x04;
PORTA = 0;
TRISB = 0;
PORTB = 0;


INTCON.GIE = 1;
INTCON.T0IE = 1;

while(1){
ir_command = 0;
ir_address = 0;
get_mark_time();
if ((mark_time > 0x80) && (mark_time < 0xb0)){
for(bitcount = 0 ; bitcount < 7 ; bitcount++){
get_mark_time();
ir_command >>= 1;
ir_command &= 0x7f;
if (mark_time > 0x38){
ir_command ^= 0x80;
}
}
ir_command >>= 1;
ir_command &= 0x7F;

for(bitcount = 0 ; bitcount < 5 ; bitcount++){
get_mark_time();
ir_address >>= 1;
ir_address &= 0x7f;
if (mark_time > 0x38){
ir_address ^= 0x80;
}
}
ir_address >>= 3;
ir_address &= 0x1F;

}

if(ir_address == 1){
if(ir_command == 0){
shadow ^= 0x01;
PORTB = shadow;
}
if(ir_command == 1){
shadow ^= 0x02;
PORTB = shadow;
}
if(ir_command == 2){
shadow ^= 0x04;
PORTB = shadow;
}
if(ir_command == 3){
shadow ^= 0x08;
PORTB = shadow;
}
if(ir_command == 4){
shadow ^= 0x10;
PORTB = shadow;
}
if(ir_command == 5){
shadow ^= 0x20;
PORTB = shadow;
}
if(ir_command == 6){
shadow ^= 0x40;
PORTB = shadow;
}
if(ir_command == 7){
shadow ^= 0x80;
PORTB = shadow;
}
if(ir_command == 8){
shadow = 0xff;
PORTB = shadow;
}
if(ir_command == 9){
shadow = 0x00;
PORTB = shadow;
}
Delay_ms(200);
}
}
}

void get_mark_time(void){
while(ir_rx);
counter=0;
TMR0 = 0;
while(!ir_rx);
mark_time = (counter << 8) + TMR0;

}
----------------------------------------------------------------------------------------------------------------------
How to use use the code to PIC16F628 , Pls help-

Regards-
Obak

hexreader
Posts: 1784
Joined: 27 Jun 2010 12:07
Location: England

Re: IR Switch SIRC Sony protocol PIC16F84A & PIC16F628

#2 Post by hexreader » 30 Sep 2015 17:45

Comparator needs to be disabled - like this:

Code: Select all

// Sony IR receiver for PIC16F628 on DIP18B of EasyPIC7 board
// put a pull-down on RB4 to make programming more reliable
// 8 MHz crystal   LEDs enabled on PORTB

sbit ir_rx at PORTA.B2;

// function prototypes
void get_mark_time(void);

// global variables
unsigned char counter = 0;
unsigned char shadow = 0;
unsigned char bitcount;
unsigned char ir_address;
unsigned char ir_command;
unsigned int mark_time;

void interrupt() {

    if (INTCON.T0IF) {
        counter++;
        INTCON.T0IF = 0;
    }
}

void main() {

    OPTION_REG = 0x04;
    TRISA = 0x04;
    PORTA = 0;
    TRISB = 0;
    PORTB = 0;
    CMCON = 0x07;                           // comparators off


    INTCON.GIE = 1;
    INTCON.T0IE = 1;

    while(1){
        ir_command = 0;
        ir_address = 0;
        get_mark_time();
        if ((mark_time > 0x80) && (mark_time < 0xb0)){
            for(bitcount = 0 ; bitcount < 7 ; bitcount++){
                get_mark_time();
                ir_command >>= 1;
                ir_command &= 0x7f;
                if (mark_time > 0x38){
                    ir_command ^= 0x80;
                }
            }
            ir_command >>= 1;
            ir_command &= 0x7F;

            for(bitcount = 0 ; bitcount < 5 ; bitcount++){
                get_mark_time();
                ir_address >>= 1;
                ir_address &= 0x7f;
                if (mark_time > 0x38){
                   ir_address ^= 0x80;
                }
            }
            ir_address >>= 3;
            ir_address &= 0x1F;

        }

        if(ir_address == 1){
            if(ir_command == 0){
                shadow ^= 0x01;
                PORTB = shadow;
            }
            if(ir_command == 1){
                shadow ^= 0x02;
                PORTB = shadow;
            }
            if(ir_command == 2){
                shadow ^= 0x04;
                PORTB = shadow;
            }
            if(ir_command == 3){
                shadow ^= 0x08;
                PORTB = shadow;
            }
            if(ir_command == 4){
                shadow ^= 0x10;
                PORTB = shadow;
            }
            if(ir_command == 5){
                shadow ^= 0x20;
                PORTB = shadow;
            }
            if(ir_command == 6){
                shadow ^= 0x40;
                PORTB = shadow;
            }
            if(ir_command == 7){
                shadow ^= 0x80;
                PORTB = shadow;
            }
            if(ir_command == 8){
                shadow = 0xff;
                PORTB = shadow;
            }
            if(ir_command == 9){
                shadow = 0x00;
                PORTB = shadow;
            }
            Delay_ms(200);
        }
    }
}

void get_mark_time(void){
    while(ir_rx);
    counter=0;
    TMR0 = 0;
    while(!ir_rx);
    mark_time = (counter << 8) + TMR0;

}
Removing all of the useful comments when you copied the code was a terrible mistake :(
I wrote the code for all to use without restriction, so there is no need to hide the code's origin by removing the comments
Uncommented code is bad code
Start every day with a smile...... (get it over with) :)

Post Reply

Return to “mikroBasic General”