Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;***************************************************************************
- ;* Description: ir remote control *mp3 kit
- ;*
- ;*
- ;* Writed at: 4nov13
- ;* Target: ATtiny2313
- ;* Author: bambangSud/kudaka
- ;* Support E-mail: [email protected], [email protected]
- ;* Home page:
- ;*
- ;* LCD rs pin connected to PD6
- ;* LCD r/w pin connected to PD5
- ;* LCD e pin connected to PD4
- ;* D4-D7 FROM LCD IS CONNECTED TO PORTD PD0-PD3
- ;* The 4x4 keypad is conected to PortB pins (PB0-PB7)
- ;* PB0,PB1,PB2,PB3 inputs, PB4,PB5,PB6,PB7 outputs
- ;* countdown timer with lcd ok 20-09-05
- ;* 24-09-05 > soal lcd paham banget
- ;* lm35 > AVR 17-12-05
- ;* 14 Januari 2006 OK (sore)
- ;* 4 jan 2011 lanjut
- ;* 15jan201 3pin OK
- ;***************************************************************************
- .include "tn2313def.inc" ;Define chip particulars
- ;***** Other equates
- .equ ignit =PB0
- .equ LED =PB1
- .equ Sign =PB2
- .equ horn =PB3
- .equ data_ =PD0
- .equ enter_ =PD1
- .equ door_ =PD2
- .equ break_ =PD3
- .equ tran_ =PD4
- .equ lat_in =PD5
- .equ lat_out =PD6
- .equ nPin =3
- ;***** Registers used by timer overflow interrupt service routine
- ;***** Global register variables
- .def nsiren =r1
- .def pin0 =r2
- .def pin1 =r3
- .def pin2 =r4
- .def pin3 =r5
- .def dpos =r6
- .def lstat =r7 // lock status
- .def second =r9
- .def minute =r10
- .def hour =r11
- .def timer =r14 ;scratch space for timer loading
- .def status =r15 ;low register to preserve status register
- //=========
- .def wreg =R16 ;General use working register
- .def timeout =R17 ;Timeout value passed to subroutine
- .def lcdstat =R18 ;LCD busy/wait status
- .def longtime=R19 ;Long timer for powerup
- .def temp =r20 ;general scratch space
- .def test =R21 ;test register
- .def monades =R22
- .def EEaddr =R23
- .def tock =r24 ;5 ms pulse
- .def sec_tmr =r25 ;storage for RTC second count
- //xyz reg
- ;.def minute =r26 ;storage for RTC minute count
- ;.def hour =r27 ;storage for RTC hour count
- ;******************************************************************
- ;* macro
- .macro buzz_on
- sbi ddrc,buzz
- sbi PORTC,buzz
- .endmacro
- .macro loadram
- ldi XH,high(@0)
- ldi XH,low(@0)
- ld temp,x
- .endmacro
- .macro stram
- ldi YH,high(@0)
- ldi YH,low(@0)
- st z,temp
- .endmacro
- ;********* Data Segment RAM ***************************************
- .dseg
- .org $60
- ram_: .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
- tock1: .db 0 ;ram for timer
- ;*****Look up table for decoding **********************************
- .eseg ;EEPROM segment
- .org 0
- table1: .db 0x00,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
- timer_table: .db 0x03,0x00,0x00 ;for store preset timer hh:mm:ss
- user_pin1: .db 1,1,1,12
- user_pin2: .db 2,2,2,12
- master_pin: .db 3,3,3,12
- pin_status: .db 0
- lock_stat: .db 0
- ;****Source code***************************************************
- .cseg ;CODE segment bootSector
- .org 0
- rjmp RESET ; Reset Handler
- nop; rjmp EXT_INT0 ; IRQ0 Handler
- nop; rjmp EXT_INT1 ; IRQ1 Handler
- nop ; Timer1 Capture Handler
- nop ; Timer1 Compare Handler
- rjmp TIM_OVF1 ; Timer1 Overflow Handler
- rjmp TIM_OVF0 ; Timer0 Overflow Handler
- nop ; UART RX Complete Handler
- nop ; UDR Empty Handler
- nop ; UART TX Complete Handler
- nop ; Analog Comparator Handler
- ;.include "lib.txt"
- ;***************************************************************************
- ; Main program entry point on reset
- reset:
- //4 2313
- ldi temp,RAMEND
- out SPL,temp ;Init Stack Pointer
- //timer0
- ldi temp,0x04 ;timer prescalar /256
- out TCCR0,temp
- ldi temp,176 ;load timer for 5 ms
- mov timer,temp
- out TCNT0,timer ;(256 - n)*256*0.2441 us
- ldi temp,0x82 ;enable timer interrupts, ICP disable
- out TIMSK,temp
- //timer1
- ;TCCR1B=0x02; // start timer (timer period = 2uS)
- LDI R30,0x00 ;// prescaller << if 0 = stop
- OUT TCCR1B,R30
- ldi temp,0x0A ;1010 = On falling edges 1111 = RisingEdges
- out MCUCR,temp
- sei ;enable global interrupts
- main:
- ;uart_: ;ubrr=(freq/16*baud)-1
- ldi R16,0x0
- ldi R17,0x47 ;2400BAUD, FOsc = 4MHz > 0x67(103)|| 9600/11.0592=0x47(71)
- out UBRRH,r16
- out UBRRL,R17
- ldi R18,(1<<rxcie|1<<Rxen)|(1<<Txen);0x0b8;%10111000 ; Enable UDRE Interrupt
- ldi R18,0x18
- out UCSRB,R18
- ldi temp,0x06
- out UCSRC,temp
- ;---------------
- ldi r21,32
- _loop:
- ldi ZH,high(ram_)
- ldi ZL,low(ram_)
- _next:
- clr tock
- rcall read_pin
- cpi tock,10
- ldi temp,1
- brsh next_2
- clr temp
- next_2:
- st Z+,temp
- dec r21
- brne _next
- rcall _dispRam
- ldi temp,'#'
- rcall putchar
- rcall bits2hex
- ldi temp,13
- rcall putchar
- ldi temp,10
- rcall putchar
- rcall longdelay
- rcall longdelay
- rcall longdelay
- ldi r21,32
- rjmp _loop
- endless: rjmp endless
- ;---------------------------------------------------------------------------/
- longdelay:
- ldi longtime,50 ;
- ldi timeout,255 ;
- puwait:
- rcall delay
- dec longtime
- brne puwait
- ret
- ;***** Delay n*64 microseconds using timer 0, delay time passed in timeout
- delay:
- ldi test,64
- cagain: dec test
- brne cagain
- dec timeout
- brne delay
- ret
- ;***************************************************************************
- blink_:
- sbis PINB,led
- rjmp blink1_
- cbi PORTB,led
- ret
- blink1_:
- sbi PORTB,led
- ret
- ;***************************************************************************
- ;***************************************************************************
- ;*
- ;* Read/Write EEPROM 00.06.15 OK (SPL)
- ;*
- ;***************************************************************************
- EEread: ;read EEprom
- sbic EECR,EEWE ;If EEWE not clear // 2000.05.30 ok
- rjmp EEread ; Wait more
- out EEAR,EEaddr ;EEprom Address Register (1200)
- sbi EECR,EERE ;set EEPROM Read strobe
- ;This instruction takes 4 clock cycles since
- ;it halts the CPU for two clock cycles
- in Temp,EEDR ;get EEprom Data Register to temp
- cbi EECR,EERE ;clr EEPROM Read strobe
- ret
- ;#######
- EEwrite: ;WriteEEprom
- sbic EECR,EEWE ;If EEWE not clear // 2000.05.30 ok
- rjmp EEWrite ; Wait more
- out EEAR,EEaddr ;EEprom Address Register (1200)
- out EEDR,temp ;store data to temp
- sbi EECR,EEMWE ;set master write enable, remove if 1200
- ;is used *000614 OK
- sbi EECR,EEWE ;set EEPROM Write strobe
- ret
- ;---------------------------------------------------------------------------/
- ;***************************************************************************
- ;****Timer Overflow Interrupt service routine******************************
- ;****Updates 5 ms, flash and debounce counter to provide RTC time reference
- ;***************************************************************************
- TIM_OVF0:
- push temp
- cli
- tick:
- in status,SREG ;preserve status register
- inc tock ;add one to 5 ms 'tock' counter
- nop ;and blink rate counter
- nop ;and bounce rate delay
- nop ;set 5 ms flag for display time
- cpi tock,200 ;is one second up?
- breq onesec ;yes, add one to seconds
- nop ;balance interrupt time
- rjmp nosecond ;no, escape
- onesec:
- inc sec_tmr
- inc second ;add one to seconds
- ;clr tock ;clear 5 ms counter
- rcall blink_
- mov temp,second
- cpi temp,60
- brne nosecond
- inc minute
- clr second
- mov temp,minute
- cpi temp,60
- brne nosecond
- inc hour
- clr minute
- nosecond:
- ldi temp,250 ;reload timer 176
- out TCNT0,temp
- out SREG,status ;restore status register
- pop temp
- sei
- reti ;return to main
- ;***************************************************************************
- ;
- ;***************************************************************************
- TIM_OVF1:; 12jan2011
- push temp
- in status,SREG ;preserve status register
- LDI R30,LOW(0xfff8)
- LDI R31,HIGH(0xffff)
- OUT TCNT1H,R31
- OUT TCNT1L,R30
- jump_:
- out SREG,status ;restore status register
- pop temp
- reti ;return to main
- ;***************************************************************************
- getchar: ; temp=getchar()
- sbis ucsra,rxc
- rjmp getchar ; loop if clear
- in temp,udr
- ret
- ;==============================
- putchar:; putchar(temp);
- sbis ucsra,udre
- rjmp putchar
- out udr,temp
- ret
- ;***************************************************************************
- read_pin: ;5nov13
- sbic PINB,0
- rjmp read_pin ;loop
- nop
- read_pin0:
- sbis PINB,0
- rjmp read_pin0
- clr temp ; reset
- nop
- read_pin1:
- ;inc temp
- sbic PINB,0
- rjmp read_pin1 ;loop
- ret
- ;***************************************************************************
- ;***************************************************************************
- hex2dec: ;convert hexa 2 ascii 2dgt (<99) 21-09-05
- push r16
- push r17
- push r18
- ldi r16,0x30
- ldi r17,0x30
- ldi r18,0x30
- dec0: cpi temp,100
- brsh dec3
- dec1: cpi temp,0x0A
- brsh dec2
- add r18,temp
- mov temp,r16
- rcall putchar
- mov temp,r17
- rcall putchar
- mov temp,r18
- rcall putchar
- pop r18
- pop r17
- pop r16
- ret
- dec2: subi temp,0x0A
- inc r17
- rjmp dec1
- dec3: subi temp,100
- inc r16
- rjmp dec0
- ;***************************************************************************
- _dispRam: ;5nov13
- ldi ZH,high(ram_+16)
- ldi ZL,low(ram_+16)
- ldi r21,16
- _dispRam1:
- ld temp,z+
- ;rcall hex2dec
- ldi r22,48
- add temp,r22
- rcall putchar
- dec r21
- brne _dispRam1
- ret
- ;***************************************************************************
- bits2hex: ; convert biner 8bits ke hexa 5nov13
- clr temp
- ldi ZH,high(ram_+16)
- ldi ZL,low(ram_+16)
- ldi r21,8
- bits2hex_1:
- ld r0,z+
- add temp,r0
- lsl temp
- dec r21
- brne bits2hex_1
- rcall hex2dec
- ret
- ;***************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment