From 0bea2e8a79f656a87781b85a5f5a6702d4de105a Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 15 Apr 2016 20:05:47 +0200 Subject: [PATCH] Few changes --- src/main.c | 50 +++++++------ src/main.c~ | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 22 deletions(-) create mode 100644 src/main.c~ diff --git a/src/main.c b/src/main.c index 7a0066e..781460d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,11 @@ +/* MIT License +Copyright (c) 2016 Daniel Treitinger +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + + + #include #include @@ -111,7 +119,7 @@ void evaluate_tastatur(char *comcode) for(a=4; a <= 7; a++) { e++; - if( ((PORTB>>a) & 1) == 0) + if( (PORTB>>a) & 1 == 0) { *comcode = e; somethingpressed = 1; @@ -131,24 +139,24 @@ void SendRc5(char* command, char *group) One(); toggle = toggle ^ 1 & 1; - if(toggle == 1) - One(); - else - Zero(); + if(toggle == 1) { + One(); } + else { + Zero(); } for(i = 4; i != 255; i--) { - if(((*group>>i))&1) - One(); - else - Zero(); + if((*group>>i)&1) { + One(); } + else { + Zero(); } } for(i = 5; i != 255; i--) { - if(((*command)>>i)&1) - One(); - else - Zero(); + if((*command>>i)&1) { + One(); } + else { + Zero(); } } delay_89ms(); @@ -156,15 +164,15 @@ void SendRc5(char* command, char *group) void main(void) -{ //Takt des PIC 4MHz, ein Zyklus = 1us +{ //Takt des PIC 4MHz, ein Zyklus = 1us unsigned char comcode = 0; char subcode = 0; OPTION_REG = 0b00000010; //Pullups on - CMCON = 0x07; //Turn of Comperators - TRISA = 0x00; //PORTA is Output - TRISB = 0xF0; //PORTB 0...3 Output - GIE = 1; //Global Interrupt Enable + CMCON = 0x07; //Turn of Comperators + TRISA = 0x00; //PORTA is Output + TRISB = 0xF0; //PORTB 0...3 Output + GIE = 1; //Global Interrupt Enable CM0 = 1; CM1 = 1; CM2 = 1; @@ -173,19 +181,17 @@ void main(void) subcode = 29; INTCON = 0; RBIE = 1; - char help = 0; while(1) { - while(!RBIF) - SLEEP(); + while(!RBIF) { + SLEEP(); } PORTB = 0xFF; evaluate_tastatur(&comcode); if(somethingpressed == 1) { SendRc5(&comcode, &subcode); somethingpressed = 0; - help = 1; } } } diff --git a/src/main.c~ b/src/main.c~ new file mode 100644 index 0000000..781460d --- /dev/null +++ b/src/main.c~ @@ -0,0 +1,200 @@ +/* MIT License +Copyright (c) 2016 Daniel Treitinger +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + + + +#include +#include + + +__CONFIG( LVP_OFF & BOREN_OFF & CPD_OFF & MCLRE_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT ); + + +unsigned char PhaseDemod(); + + +//Global +unsigned char toggle = 0; +unsigned int CountA, CountB, CountC; +unsigned int somethingpressed = 0; + +void samplebit(); + +void ON() +{ + unsigned char i = 0; + do + { + RA0 = 1; // 6-7us on + RA0 = 1; + RA0 = 1; + RA0 = 1; + + RA0 = 0; // 21-22 us of + RA0 = 0; + RA0 = 0; + RA0 = 0; + RA0 = 0; + RA0 = 0; + RA0 = 0; + RA0 = 0; + RA0 = 0; + RA0 = 0; + RA0 = 0; + i++; + } + while(i<32); + RA0 = 0; +} + +void OFF() +{ + unsigned char i = 0; + do + { + RA0=0; + } + while(i++<59); +} + + + + +void interrupt ISR (void) +{ + +} + +void delay_89ms() +{ +#asm + pause89ms + clrf _CountA + clrf _CountB + clrf _CountC + movlw 0x74 + movwf _CountB + movlw 0x02 + movwf _CountA + movlw 0x01 + movwf _CountC + + Loop ;Wiederholung der Zeitverzögerung + decfsz _CountA + goto Loop + decfsz _CountB + goto Loop + decfsz _CountC + goto Loop +#endasm + return; +} + +void One() +{ + OFF(); + ON(); +} +void Zero() +{ + ON(); + OFF(); +} + + +void evaluate_tastatur(char *comcode) +{ + unsigned char i; + unsigned char a; + unsigned char e; + e = 0; + + for(i=3; i != 255; i--) + { + PORTB = 0xFF; + PORTB &= ~(1<>a) & 1 == 0) + { + *comcode = e; + somethingpressed = 1; + return; + } + + + } + } + +} + +void SendRc5(char* command, char *group) +{ + unsigned char i; + One(); + One(); + + toggle = toggle ^ 1 & 1; + if(toggle == 1) { + One(); } + else { + Zero(); } + + for(i = 4; i != 255; i--) + { + if((*group>>i)&1) { + One(); } + else { + Zero(); } + } + for(i = 5; i != 255; i--) + { + if((*command>>i)&1) { + One(); } + else { + Zero(); } + } + delay_89ms(); + +} + + +void main(void) +{ //Takt des PIC 4MHz, ein Zyklus = 1us + unsigned char comcode = 0; + char subcode = 0; + + OPTION_REG = 0b00000010; //Pullups on + CMCON = 0x07; //Turn of Comperators + TRISA = 0x00; //PORTA is Output + TRISB = 0xF0; //PORTB 0...3 Output + GIE = 1; //Global Interrupt Enable + CM0 = 1; + CM1 = 1; + CM2 = 1; + PORTA = 0; + PORTB = 0xFF; + subcode = 29; + INTCON = 0; + RBIE = 1; + + while(1) + { + while(!RBIF) { + SLEEP(); } + PORTB = 0xFF; + evaluate_tastatur(&comcode); + if(somethingpressed == 1) + { + SendRc5(&comcode, &subcode); + somethingpressed = 0; + } + } +} + + +