![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Dear all~~~ I have a Sony IR decode Project. I am using Hi-tech C program language. My hardware is PIC16F877A whit 4M crystal. I want to use CCP module. I have find sample code in Google. But it can not work correctly. The CCPR1 is always not Sony IR code. Does anyone have Hi-tech C sample code for me??? THX | |
| |
| | #2 |
|
You said so yourself, you already have sample code. Figure out what's wrong with what you have.
__________________ "Because I be what I be. I would tell you what you want to know if I could, mum, but I be a cat, and no cat anywhere ever gave anyone a straight answer, har har." | |
| |
| | #3 |
|
There's code in assembler in my tutorials, but perhaps more helpful for you there's a description of how SIRC's works.
| |
| |
| | #4 |
|
Hey Nigel 1 question. When sending SIRC i know one must send out pulses to make the data aka start, one, zero but when receiving the data it comes back as solid blocks? Like i just have to read the start and see how long it is right? it doesnt receive actual pulses right like i wont have to read the PULSES right?
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #5 |
|
The TSOP1138 (or equivalent) removes the carrier.
| |
| |
| | #6 |
|
yay! i think i finally understand it then. Thanks Bill and Nigel.
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #7 | |
| Quote:
Experimenting with IR Remotes using a PIC running BoostC Project - Open Circuits | ||
| |
| | #8 |
|
Gosh Russ, it would take me less time to research and implement my own algorithms and method from scratch rather than try to analyze the stuff you have spread out across all those files (grin)...
| |
| |
| | #9 |
|
OMG i did it.: Code: /* **************************************************************************
; *
; Filename: SIRC *
; Date: May 29, 2009 *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;****************************************************************************
; Notes:
; I am delaying in this code a nice even number every 200uS. Mainly because if
; i count each pulse it would be accurate but too many counts for a char type
; and i dont want to use a int. So i can get a 600 count by skipping every 300uS
; and the count will be a nice low number...3
;
; For a 1.2mS aka HIGH i should get a count of 6 and for the start 2.4mS i should
; get a count of 12. Since this isnt too accurate i range it about 1-2 numbers
; above or below the standard.
;
;****************************************************************************
*/
#include <p18f2525.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF
unsigned char lTime;
unsigned char ir_add;
unsigned char ir_cmd;
#define irTris TRISCbits.TRISC4
#define irPin PORTCbits.RC4
void main(void);
void GetSIRC(void);
void main(void){
OSCCON = 0x72; //8MHz clock
while(!OSCCONbits.IOFS); //wait for osc stable
irTris = 1;
GetSIRC();
while(1);
}
void GetSIRC(unsigned char *address, unsigned char *command){
char x;
StartLook:
ir_add = ir_cmd = 0;
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime <= 10) //Start too short
goto StartLook; //Restart
if(lTime >= 14) //Start too long
goto StartLook; //Restart
lTime = 0;
for(x=0;x<7;x++){ //repeat 7 times for command
ir_cmd >>= 1; //if it was skipped or is done ORing then shift over the 1
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime >= 6) //If its high then OR a 1 in else skip
ir_cmd |= 0x40; //if its less than 6 its a 0 so dont OR it
}
for(x=0;x<5;x++){ //repeat 5 times for address/device
ir_add >>= 1; //if it was skipped or is done ORing then shift over the 1
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime >= 6) //If its high then OR a 1 in else skip
ir_add |= 0x10; //if its less than 6 its a 0 so dont OR it
}
}
I fixed it up and commented like crazy... even a top part for how it works.
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 30th May 2009 at 02:45 AM. | |
| |
| | #10 |
|
Wanna use a POINTER instead then here ya go: Code: /* **************************************************************************
; *
; Filename: SIRC *
; Date: May 29, 2009 *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;****************************************************************************
; Notes:
; I am delaying in this code a nice even number every 200uS. Mainly because if
; i count each pulse it would be accurate but too many counts for a char type
; and i dont want to use a int. So i can get a 600 count by skipping every 300uS
; and the count will be a nice low number...3
;
; For a 1.2mS aka HIGH i should get a count of 6 and for the start 2.4mS i should
; get a count of 12. Since this isnt too accurate i range it about 1-2 numbers
; above or below the standard.
;
;****************************************************************************
*/
#include <p18f2525.h>
#include <delays.h>
#include <string.h>
#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF
unsigned char lTime;
unsigned char MyAdd;
unsigned char MyCmd;
#define irTris TRISCbits.TRISC4
#define irPin PORTCbits.RC4
void main(void);
void GetSIRC(unsigned char *address, unsigned char *command);
void main(void){
OSCCON = 0x72; //8MHz clock
while(!OSCCONbits.IOFS); //wait for osc stable
irTris = 1;
GetSIRC(&MyAdd,&MyCmd);
while(1);
}
void GetSIRC(unsigned char *address, unsigned char *command){
unsigned char ir_add;
unsigned char ir_cmd;
char x;
StartLook:
ir_add = ir_cmd = 0;
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime <= 10) //Start too short
goto StartLook; //Restart
if(lTime >= 14) //Start too long
goto StartLook; //Restart
lTime = 0;
for(x=0;x<7;x++){ //repeat 7 times for command
ir_cmd >>= 1; //if it was skipped or is done ORing then shift over the 1
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime >= 6) //If its high then OR a 1 in else skip
ir_cmd |= 0x40; //if its less than 6 its a 0 so dont OR it
}
for(x=0;x<5;x++){ //repeat 5 times for address/device
ir_add >>= 1; //if it was skipped or is done ORing then shift over the 1
while(irPin); //wait for it to be low
lTime = 0; //reset the counter
while(irPin == 0){ //while the pin is low which is our pulse count
lTime++; //increment every 200uS until pin is high
Delay100TCYx(4); //200uS delay
}
if(lTime >= 6) //If its high then OR a 1 in else skip
ir_add |= 0x10; //if its less than 6 its a 0 so dont OR it
}
*address = ir_add;
*command = ir_cmd;
}
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 30th May 2009 at 02:56 AM. | |
| |
| | #11 |
|
Very nice Jason (AtomSoft), and all in a single file too (grin)... So it seems Sony SIRC is something like this with base timing in intervals of 550 to 600 usecs? Last edited by Mike, K8LH; 30th May 2009 at 02:04 AM. | |
| |
| | #12 |
|
Yeah exactly! Thanks! I also fixed the code on both my post here. The code is at 100% (i hope)
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics | |
| |
| | #13 |
|
A couple more questions about SIRC, please? (1) Is the signal from the TSOP1138 type decoders "active low" when it's receiving the IR signal (signals reversed from my drawing above)? (2) Do those signal times vary considerably? | |
| |
| | #14 | ||
| Quote:
Quote:
So my tutorial doesn't check for specific pulse widths, but if it's within a certain range or not, here's the actual code, the values are simply scaled to fit within a single byte, and have no precise meaning. Code: ; test if Zero, One, or Start (or error) Chk_Pulse clrf Flags TryError movf LoX, w ; check if pulse too small addlw d'255' - d'20' ; if LoX <= 20 btfsc STATUS , C goto TryZero bsf Flags, ErrFlag ; Error found, set flag retlw 0x00 TryZero movf LoX, w ; check if zero addlw d'255' - d'60' ; if LoX <= 60 btfsc STATUS , C goto TryOne bsf Flags, Zero ; Zero found, set flag retlw 0x00 TryOne movf LoX, w ; check if one addlw d'255' - d'112' ; if LoX <= 112 btfsc STATUS , C goto TryStart bsf Flags, One ; One found, set flag retlw 0x00 TryStart movf LoX, w ; check if start addlw d'255' - d'180' ; if LoX <= 180 btfsc STATUS , C goto NoMatch bsf Flags, StartFlag ; Start pulse found retlw 0x00 NoMatch ; pulse too long bsf Flags, ErrFlag ; Error found, set flag retlw 0x00 ;end of pulse measuring routines | |||
| |
| | #15 |
|
Im not 100% sure on my Receiver Part But I checked it with the PICKIT 2 Logic software and it seems to be active low. And inactive high. It maybe just my part now sure. I dont even have info on it. Ill try other receiver peice i have here and see if i get same results ok. EDIT: HEH i guess Nigel cleared that up
__________________ AtomSofts eBay Store AtomSoftTech: C18 TIPS & TRICKS v9 PDF Nokia 6100 Driver/Software My Name: Jason Lopez http://atomsofttech.info/ | My YouTube Videos! My Favorite Store: dipmicro Electronics Last edited by AtomSoft; 30th May 2009 at 12:27 PM. | |
| |
|
| Tags |
| decode, hitech, pica, sony |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Which IR protocal is easier to decode, Sony SIRC or Philips RC5 | blueroomelectronics | Micro Controllers | 5 | 14th January 2008 01:17 AM |
| How to decode.... | arustu | Electronic Projects Design/Ideas/Reviews | 5 | 1st August 2006 10:44 AM |
| bs2pe read decode | egg0900 | Micro Controllers | 3 | 20th June 2005 11:06 PM |
| IR (Encode and Decode signals) | Bella | Micro Controllers | 0 | 27th October 2003 06:46 AM |