+ Reply to Thread
Page 1 of 2
1 2 Last
Results 1 to 15 of 27

Thread: ATtiny2313 SIRC help please

  1. #1
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default ATtiny2313 SIRC help please

    Hey guys i know not many AVR users here and most are using C perhaps but here is my code. Im not sure whats wrong tho. I know my 2313 is running at 8mhz i checked the fuses.

    Code:
    .include "tn2313def.inc" 
    .def MyIr = R14
    .def Temp = R15
    .def devTmp = R16		
    .def cmdTmp = R17
    .def mask = R18
    	
    .def d1 = R20 	
    .def d2 = R21 	
    .def d3 = R22
    .def sPulse = R23
     	
    .org 0x0000 			
        rjmp RESET 			
    
    RESET: 	
        ldi sPulse, 0x0C        ;12 * (200us) = 2.4mS
        ldi d1, 0x00
        ldi d2, 0x00
        ldi d3, 0x00
        ldi cmdTmp,0x00
        ldi devTmp,0x00
    	ldi mask,0b11111110
    
    	out DDRB,mask ; port B all outputs except PB0
    	out PORTB,d1  ; disable pullups and set all low
    MainLoop:
        rcall   GetSirc
        cpi     cmdTmp,0x01
    	brne	notcorr
    correct:
    	sbi     PORTB,1
    	rjmp    MainLoop
    notcorr:
    	cbi     PORTB,1
    	rjmp    MainLoop
    	
    GetSirc:
        rcall   WaitLow
    GetStart:
        inc     d1
        rcall   Delay200uS
        in      MyIR,PINB
        sbrs    MyIR,0         ;Check if pin hi/lo
        rjmp    GetStart       ;Pin still low add more
        cpi     d1,0x0B        ;The pin is now high
        brlo    GetSirc        ;if the count is less than 11 bad start
        cpi     d1,0x0E        ;if the count is equal to or geater than 14 bad start
        brsh    GetSirc
    
        ldi     d1, 0x00       ;If it made it here the start pulse was ok
        ldi     d2, 0x07
    GetSeven:
        dec     d2
        lsr     cmdTmp
    repeatS:
        rcall   WaitLow
        inc     d1
        rcall   Delay200uS
        in      MyIR,PINB
        sbrs    MyIR,0          ;Check if pin hi/lo
        rjmp    repeatS         ;If pin still low repeat
    
        cpi     d1,0x05
        brlo    DoneOring  
        ori     cmdTmp,$40
    DoneOring:
        cpi     d2, 0x00        ;Check if collected 7 bits
        brne    GetSeven
        ldi     d1, 0x00
        ldi     d2, 0x05
    GetFive:    
        dec     d2
        lsr     devTmp
    repeatF:
        rcall   WaitLow
        inc     d1
        rcall   Delay200uS
        in      MyIR,PINB
        sbrs    MyIR,0          ;Check if pin hi/lo
        rjmp    repeatF         ;If pin still low repeat
    
        cpi     d1,0x05
        brlo    DoneOring2  
        ori     devTmp,$10
    DoneOring2:
        cpi     d2, 0x00        ;Check if collected 7 bits
        brne    GetFive
        ldi     d1, 0x00
        ldi     d2, 0x00
        ret
    
    Delay200uS:                ;delay 202us @ 8mhz 
        ldi     d1, $06
    L2:
        ldi     d2, $59
    L3:
        dec     d2         
        brne    L3        
        dec     d1         
        brne    L2        
        ret
    
    WaitLow:
        in      MyIR,PINB
        sbrc    MyIR,0
        rjmp    WaitLow
        ret
    
    im i checking the data from a pin ok?
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange


  2. #2
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    I fixed it it had to do with the stack pointer
    Code:
    .include "tn2313def.inc" 
    .def devTmp = R16		
    .def cmdTmp = R17
    .def mask = R18
    .def temp = R19
    .def d1 = R20 	
    .def d2 = R21 	
    .def d3 = R22
    .def sPulse = R23
    .def MyIr = R24
    .def d4 = R25
     	
    .org 0x0000 			
     
    RESET: 
    	ldi R26,RAMEND    ; Initial Stack Pointer to SRAM END address (RAMEND)       
        out SPL,R26       ; Stack Pointer (SP) = RAMEND	
        ldi sPulse, 0x0C        ;12 * (200us) = 2.4mS
        ldi d1, 0x00
        ldi d2, 0x00
        ldi d3, 0x00
        ldi cmdTmp,0x00
        ldi devTmp,0x00
    	ldi temp,0x01
    	ldi mask,0b11111110
    
    	out DDRB,mask ; port B all outputs
    	out PORTB,temp ; initialize port B
    MainLoop:
    	rcall   Delay100mS
    	clr		d1
    	clr		d2
    	clr		d3
        clr 	cmdTmp
        rcall   GetSirc
    
    	sbi     PORTB,1
        cpi     cmdTmp,0x06
    	brne	DoneM
    	cbi     PORTB,1
    DoneM:
    	rjmp    MainLoop
    try2:
    	sbi     PORTB,1
    	rjmp    MainLoop
    	
    GetSirc:
        rcall   WaitLow
    GetStart:
        inc     d3
        rcall   Delay200uS
    	SBIC 	PINB,0
        rjmp    GetStart       ;Pin still low add more
        cpi     d3,11        ;The pin is now high
        brlo    GetSirc        ;if the count is less than 11 bad start
        cpi     d3,13        ;if the count is equal to or geater than 14 bad start
        brsh    GetSirc
    
        ldi     d3, 0x00       ;If it made it here the start pulse was ok
        ldi     d4, 0x07
    
    GetSeven:
        dec     d4
        lsr     cmdTmp
    repeatS:
        rcall   WaitLow
        inc     d3
        rcall   Delay200uS
    	SBIC 	PINB,0
        rjmp    repeatS         ;If pin still low repeat
    
        cpi     d3,0x05
        brlo    DoneOring  
        ori     cmdTmp,$40
    DoneOring:
        cpi     d4, 0x00        ;Check if collected 7 bits
        brne    GetSeven
    
    
        ldi     d3, 0x00
        ldi     d4, 0x05
    GetFive:    
        dec     d4
        lsr     devTmp
    repeatF:
        rcall   WaitLow
        inc     d3
        rcall   Delay200uS
    	SBIC 	PINB,0
        rjmp    repeatF         ;If pin still low repeat
    
        cpi     d3,0x05
        brlo    DoneOring2  
        ori     devTmp,$10
    DoneOring2:
        cpi     d4, 0x00        ;Check if collected 7 bits
        brne    GetFive
        ldi     d3, 0x00
        ldi     d4, 0x00
        ret
    
    Delay200uS:                ;delay 202us @ 8mhz 
        ldi     d1, $06
    L2:
        ldi     d2, $59
    L3:
        dec     d2         
        brne    L3        
        dec     d1         
        brne    L2        
        ret
    
    WaitLow:
    	SBIS 	PINB,0
        rjmp    WaitLow
        ret
    ; ============================= 
    ;    delay loop generator 
    ;     800000 cycles: (100mS)
    ; ----------------------------- 
    ; delaying 799995 cycles:
    Delay100mS:
              ldi  d1, $5F
    WGLOOP0:  ldi  d2, $17
    WGLOOP1:  ldi  d3, $79
    WGLOOP2:  dec  d3
              brne WGLOOP2
              dec  d2
              brne WGLOOP1
              dec  d1
              brne WGLOOP0
    ; ----------------------------- 
    ; delaying 3 cycles:
              ldi  d1, $01
    WGLOOP3:  dec  d1
              brne WGLOOP3
    ; ----------------------------- 
    ; delaying 2 cycles:
              nop
              nop
    ; ============================= 
    		  ret
    
    I got it to work when i press button 7 aka 0x06 . I chose a nice number to test. The issue is it works 1 time. Like when i press the wrong number or button it should turn off the LED but no luck
    Last edited by AtomSoft; 5th June 2009 at 10:23 PM.
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  3. #3
    Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent
    Join Date
    Oct 2006
    Location
    Rochester, NY U.S.
    Posts
    9,826
    Blog Entries
    1

    Default

    Have you verified those delay loop lengths? Also if you're going to continue programming in ASM you should probably make a custom delay subroutine/macro you have one for 100ms and one for 200ms when you should just have a single routine that you push a few bytes on the stack to set the length.
    Nothing jumped out and bit me right away, but my AVR ASM is rusty.
    "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."

  4. #4
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    delays are fine. 200us & 100ms
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  5. #5
    Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent Sceadwian Excellent
    Join Date
    Oct 2006
    Location
    Rochester, NY U.S.
    Posts
    9,826
    Blog Entries
    1

    Default

    NPPC Software for ATMEL MCU programming
    Might be someplace you'll want to visit, looks good from a first glance for re-creating a stimulus file so you can simulate what's going on in code with a given input signal.
    "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."

  6. #6
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    hey i got tired of ASM so i went to C and yay got it working:
    Code:
        #define F_CPU 1000000UL                                    /* Clock Frequency = 1Mhz */
    
        #include <inttypes.h>
        #include <avr/io.h>
        #include <util/delay.h>
    
    	#define irPin (PINB & (1<<PINB0))
    
        unsigned char ir_add;
        unsigned char ir_cmd;
    
    
    void GetSIRC(){
        char x;
    	char lTime;
    
    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
            _delay_us(200);         //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
                _delay_us(200);     //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
                _delay_us(200);     //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			
        }
    
    }
    
    int main(){                         // The main function
    
    	DDRB = 0b11111110;                  // Set all the pins of PortB as output (PB0 = input)
    
    
        while (1) {                         // Set up an infinite loop
    		GetSIRC();
    		if(ir_cmd == 0x06)
    			PORTB|=(1<<PB1);
    		else
    			PORTB&=~(1<<PB1);
    
    		_delay_ms(200);
        }
    }
    
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  7. #7
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Jason you no any C18 cheat sheets That code looks a lot easier then on the pic good work. Jason
    Burt

  8. #8
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    I dont have any cheat sheets sorry. But i might create a cheat sheet come to think of it. I seem to forget alot of codes and there are alot of handy things there so . Ill try to make a cheat sheet for me and of course share it.

    C is so cool tho i be a cheat sheet would work across platforms like a C18 would be similar to a SourceBoostC and AVR-GCC cheat sheet.


    Hey Burt do me a favor and check it my website link works.. and replay back with its status like if its online or not. Im hosting off my PC for now but not sure if i setup correctly.

    EDIT
    You know what got me lost first...
    The values are inverted lol

    Like for a PIC to set a pin as input you would:
    TRISA= 0b11111111; // The 1 = Input and 0 = Output

    But for a AVR its:
    DDRA = 0b00000000; // The 0 = Input and 1 = Output
    Last edited by AtomSoft; 6th June 2009 at 12:39 PM.
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  9. #9
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Yep your hot and on line and using no-ip I like no-ip
    Burt

  10. #10
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    Quote Originally Posted by be80be View Post
    Yep your hot and on line and using no-ip I like no-ip
    Heh thanks dude. Ill try to post a cheat sheet soon!
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  11. #11
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,745

    Default

    I found this dude:
    http://pauljmac.com/uploads/PIC%20c%20cheat%20sheet.pdf

    I guess ill use it as a start. Ill create something very nice soon!
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

  12. #12
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,791

    Default

    I'd just like to say, I'm seriously impressed with the amount of work Atomsoft is doing, and how fast he does it.

    Presumably he's not married?
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  13. #13
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Presumably he's not married?
    And no Girlfriend Lol he burned that ATtiny2313 up I was thinking where did he get the time myself. Every time I get some thing going I have to stop and take my kids some where then when I get back. I have to rethink what I was doing. I got me a laptop and take them skating that gets me 4 hour and no beating the door down to go some where.
    P.S. that's why I ask about the cheat sheet
    Burt

  14. #14
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,791

    Default

    Quote Originally Posted by be80be View Post
    And no Girlfriend Lol he burned that ATtiny2313 up I was thinking where did he get the time myself. Every time I get some thing going I have to stop and take my kids some where then when I get back. I have to rethink what I was doing. I got me a laptop and take them skating that gets me 4 hour and no beating the door down to go some where.
    P.S. that's why I ask about the cheat sheet
    Don't mention kids!!!.

    Mu daughter passed her driving test this week

    I'm currently at work car-less, hoping she remembers to come and pick me up later Not to mention, adding her to my insurance has quadrupled my insurance costs!,
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  15. #15
    be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent be80be Excellent
    Join Date
    Aug 2008
    Location
    morristown,tn
    Posts
    2,000

    Default

    Don't mention kids!!!.

    Mu daughter passed her driving test this week

    I'm currently at work car-less, hoping she remembers to come and pick me up later Not to mention, adding her to my insurance has quadrupled my insurance costs!,
    I don't even want to think about that I have twins Girls. they be driving at the same time.
    Burt

+ Reply to Thread
Page 1 of 2
1 2 Last

Similar Threads

  1. SIRC Question
    By UTMonkey in forum Micro Controllers
    Replies: 8
    Latest: 22nd August 2008, 12:01 AM
  2. Nigels SIRC Coding Some Doubts
    By Suraj143 in forum Micro Controllers
    Replies: 11
    Latest: 31st March 2008, 03:51 AM
  3. JuneBug SIRC RX - Complete
    By UTMonkey in forum Micro Controllers
    Replies: 71
    Latest: 4th March 2008, 12:09 PM
  4. Which IR protocal is easier to decode, Sony SIRC or Philips RC5
    By blueroomelectronics in forum Micro Controllers
    Replies: 5
    Latest: 14th January 2008, 12:17 AM
  5. attiny2313
    By eng1 in forum Micro Controllers
    Replies: 5
    Latest: 27th October 2007, 11:40 PM

Tags for this Thread