bambangSud

IR remote control receiver

Nov 21st, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. ;***************************************************************************
  2. ;* Description: ir remote control *mp3 kit
  3. ;*
  4. ;*
  5. ;* Writed at: 4nov13
  6. ;* Target: ATtiny2313
  7. ;* Author: bambangSud/kudaka
  8. ;* Home page:
  9. ;*
  10. ;* LCD rs pin connected to PD6
  11. ;* LCD r/w pin connected to PD5
  12. ;* LCD e pin connected to PD4
  13. ;* D4-D7 FROM LCD IS CONNECTED TO PORTD PD0-PD3
  14. ;* The 4x4 keypad is conected to PortB pins (PB0-PB7)
  15. ;* PB0,PB1,PB2,PB3 inputs, PB4,PB5,PB6,PB7 outputs
  16. ;* countdown timer with lcd ok 20-09-05
  17. ;* 24-09-05 > soal lcd paham banget
  18. ;* lm35 > AVR 17-12-05
  19. ;* 14 Januari 2006 OK (sore)
  20. ;* 4 jan 2011 lanjut
  21. ;* 15jan201 3pin OK
  22. ;***************************************************************************
  23.  
  24. .include "tn2313def.inc" ;Define chip particulars
  25.  
  26. ;***** Other equates
  27. .equ ignit =PB0
  28. .equ LED =PB1
  29. .equ Sign =PB2
  30. .equ horn =PB3
  31.  
  32. .equ data_ =PD0
  33. .equ enter_ =PD1
  34. .equ door_ =PD2
  35. .equ break_ =PD3
  36. .equ tran_ =PD4
  37. .equ lat_in =PD5
  38. .equ lat_out =PD6
  39. .equ nPin =3
  40. ;***** Registers used by timer overflow interrupt service routine
  41.  
  42. ;***** Global register variables
  43. .def nsiren =r1
  44. .def pin0 =r2
  45. .def pin1 =r3
  46. .def pin2 =r4
  47. .def pin3 =r5
  48. .def dpos =r6
  49. .def lstat =r7 // lock status
  50.  
  51. .def second =r9
  52. .def minute =r10
  53. .def hour =r11
  54.  
  55. .def timer =r14 ;scratch space for timer loading
  56. .def status =r15 ;low register to preserve status register
  57. //=========
  58. .def wreg =R16 ;General use working register
  59. .def timeout =R17 ;Timeout value passed to subroutine
  60. .def lcdstat =R18 ;LCD busy/wait status
  61. .def longtime=R19 ;Long timer for powerup
  62. .def temp =r20 ;general scratch space
  63. .def test =R21 ;test register
  64. .def monades =R22
  65. .def EEaddr =R23
  66.  
  67. .def tock =r24 ;5 ms pulse
  68. .def sec_tmr =r25 ;storage for RTC second count
  69.  
  70. //xyz reg
  71. ;.def minute =r26 ;storage for RTC minute count
  72. ;.def hour =r27 ;storage for RTC hour count
  73.  
  74.  
  75. ;******************************************************************
  76. ;* macro
  77. .macro buzz_on
  78. sbi ddrc,buzz
  79. sbi PORTC,buzz
  80. .endmacro
  81.  
  82. .macro loadram
  83. ldi XH,high(@0)
  84. ldi XH,low(@0)
  85. ld temp,x
  86. .endmacro
  87.  
  88. .macro stram
  89. ldi YH,high(@0)
  90. ldi YH,low(@0)
  91. st z,temp
  92. .endmacro
  93.  
  94. ;********* Data Segment RAM ***************************************
  95. .dseg
  96. .org $60
  97. ram_: .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  98.  
  99.  
  100. tock1: .db 0 ;ram for timer
  101. ;*****Look up table for decoding **********************************
  102. .eseg ;EEPROM segment
  103. .org 0
  104.  
  105. table1: .db 0x00,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
  106. timer_table: .db 0x03,0x00,0x00 ;for store preset timer hh:mm:ss
  107. user_pin1: .db 1,1,1,12
  108. user_pin2: .db 2,2,2,12
  109. master_pin: .db 3,3,3,12
  110. pin_status: .db 0
  111. lock_stat: .db 0
  112. ;****Source code***************************************************
  113. .cseg ;CODE segment bootSector
  114. .org 0
  115. rjmp RESET ; Reset Handler
  116. nop; rjmp EXT_INT0 ; IRQ0 Handler
  117. nop; rjmp EXT_INT1 ; IRQ1 Handler
  118. nop ; Timer1 Capture Handler
  119. nop ; Timer1 Compare Handler
  120. rjmp TIM_OVF1 ; Timer1 Overflow Handler
  121. rjmp TIM_OVF0 ; Timer0 Overflow Handler
  122. nop ; UART RX Complete Handler
  123. nop ; UDR Empty Handler
  124. nop ; UART TX Complete Handler
  125. nop ; Analog Comparator Handler
  126.  
  127. ;.include "lib.txt"
  128. ;***************************************************************************
  129.  
  130. ; Main program entry point on reset
  131.  
  132. reset:
  133. //4 2313
  134. ldi temp,RAMEND
  135. out SPL,temp ;Init Stack Pointer
  136.  
  137. //timer0
  138. ldi temp,0x04 ;timer prescalar /256
  139. out TCCR0,temp
  140. ldi temp,176 ;load timer for 5 ms
  141. mov timer,temp
  142. out TCNT0,timer ;(256 - n)*256*0.2441 us
  143. ldi temp,0x82 ;enable timer interrupts, ICP disable
  144. out TIMSK,temp
  145.  
  146. //timer1
  147. ;TCCR1B=0x02; // start timer (timer period = 2uS)
  148. LDI R30,0x00 ;// prescaller << if 0 = stop
  149. OUT TCCR1B,R30
  150.  
  151. ldi temp,0x0A ;1010 = On falling edges 1111 = RisingEdges
  152. out MCUCR,temp
  153. sei ;enable global interrupts
  154.  
  155. main:
  156. ;uart_: ;ubrr=(freq/16*baud)-1
  157. ldi R16,0x0
  158. ldi R17,0x47 ;2400BAUD, FOsc = 4MHz > 0x67(103)|| 9600/11.0592=0x47(71)
  159. out UBRRH,r16
  160. out UBRRL,R17
  161. ldi R18,(1<<rxcie|1<<Rxen)|(1<<Txen);0x0b8;%10111000 ; Enable UDRE Interrupt
  162. ldi R18,0x18
  163. out UCSRB,R18
  164. ldi temp,0x06
  165. out UCSRC,temp
  166. ;---------------
  167. ldi r21,32
  168.  
  169. _loop:
  170. ldi ZH,high(ram_)
  171. ldi ZL,low(ram_)
  172.  
  173. _next:
  174. clr tock
  175. rcall read_pin
  176. cpi tock,10
  177. ldi temp,1
  178. brsh next_2
  179. clr temp
  180. next_2:
  181. st Z+,temp
  182.  
  183. dec r21
  184. brne _next
  185.  
  186. rcall _dispRam
  187. ldi temp,'#'
  188. rcall putchar
  189. rcall bits2hex
  190.  
  191. ldi temp,13
  192. rcall putchar
  193.  
  194. ldi temp,10
  195. rcall putchar
  196.  
  197. rcall longdelay
  198. rcall longdelay
  199. rcall longdelay
  200.  
  201. ldi r21,32
  202.  
  203.  
  204. rjmp _loop
  205. endless: rjmp endless
  206. ;---------------------------------------------------------------------------/
  207.  
  208. longdelay:
  209. ldi longtime,50 ;
  210. ldi timeout,255 ;
  211. puwait:
  212. rcall delay
  213. dec longtime
  214. brne puwait
  215. ret
  216.  
  217. ;***** Delay n*64 microseconds using timer 0, delay time passed in timeout
  218. delay:
  219. ldi test,64
  220. cagain: dec test
  221. brne cagain
  222. dec timeout
  223. brne delay
  224. ret
  225.  
  226. ;***************************************************************************
  227.  
  228.  
  229. blink_:
  230. sbis PINB,led
  231. rjmp blink1_
  232. cbi PORTB,led
  233. ret
  234.  
  235. blink1_:
  236. sbi PORTB,led
  237. ret
  238. ;***************************************************************************
  239. ;***************************************************************************
  240. ;*
  241. ;* Read/Write EEPROM 00.06.15 OK (SPL)
  242. ;*
  243. ;***************************************************************************
  244. EEread: ;read EEprom
  245. sbic EECR,EEWE ;If EEWE not clear // 2000.05.30 ok
  246. rjmp EEread ; Wait more
  247. out EEAR,EEaddr ;EEprom Address Register (1200)
  248. sbi EECR,EERE ;set EEPROM Read strobe
  249. ;This instruction takes 4 clock cycles since
  250. ;it halts the CPU for two clock cycles
  251. in Temp,EEDR ;get EEprom Data Register to temp
  252. cbi EECR,EERE ;clr EEPROM Read strobe
  253. ret
  254. ;#######
  255. EEwrite: ;WriteEEprom
  256. sbic EECR,EEWE ;If EEWE not clear // 2000.05.30 ok
  257. rjmp EEWrite ; Wait more
  258. out EEAR,EEaddr ;EEprom Address Register (1200)
  259. out EEDR,temp ;store data to temp
  260. sbi EECR,EEMWE ;set master write enable, remove if 1200
  261. ;is used *000614 OK
  262. sbi EECR,EEWE ;set EEPROM Write strobe
  263. ret
  264.  
  265.  
  266. ;---------------------------------------------------------------------------/
  267. ;***************************************************************************
  268. ;****Timer Overflow Interrupt service routine******************************
  269. ;****Updates 5 ms, flash and debounce counter to provide RTC time reference
  270. ;***************************************************************************
  271. TIM_OVF0:
  272. push temp
  273. cli
  274. tick:
  275. in status,SREG ;preserve status register
  276. inc tock ;add one to 5 ms 'tock' counter
  277. nop ;and blink rate counter
  278. nop ;and bounce rate delay
  279. nop ;set 5 ms flag for display time
  280. cpi tock,200 ;is one second up?
  281. breq onesec ;yes, add one to seconds
  282. nop ;balance interrupt time
  283. rjmp nosecond ;no, escape
  284.  
  285. onesec:
  286. inc sec_tmr
  287. inc second ;add one to seconds
  288. ;clr tock ;clear 5 ms counter
  289.  
  290. rcall blink_
  291.  
  292. mov temp,second
  293. cpi temp,60
  294. brne nosecond
  295. inc minute
  296. clr second
  297.  
  298. mov temp,minute
  299. cpi temp,60
  300. brne nosecond
  301. inc hour
  302. clr minute
  303.  
  304. nosecond:
  305. ldi temp,250 ;reload timer 176
  306. out TCNT0,temp
  307. out SREG,status ;restore status register
  308. pop temp
  309. sei
  310. reti ;return to main
  311.  
  312. ;***************************************************************************
  313. ;
  314. ;***************************************************************************
  315. TIM_OVF1:; 12jan2011
  316. push temp
  317. in status,SREG ;preserve status register
  318.  
  319. LDI R30,LOW(0xfff8)
  320. LDI R31,HIGH(0xffff)
  321. OUT TCNT1H,R31
  322. OUT TCNT1L,R30
  323.  
  324.  
  325. jump_:
  326. out SREG,status ;restore status register
  327. pop temp
  328. reti ;return to main
  329.  
  330.  
  331. ;***************************************************************************
  332. getchar: ; temp=getchar()
  333. sbis ucsra,rxc
  334. rjmp getchar ; loop if clear
  335. in temp,udr
  336. ret
  337. ;==============================
  338. putchar:; putchar(temp);
  339. sbis ucsra,udre
  340. rjmp putchar
  341. out udr,temp
  342. ret
  343.  
  344. ;***************************************************************************
  345. read_pin: ;5nov13
  346. sbic PINB,0
  347. rjmp read_pin ;loop
  348. nop
  349.  
  350. read_pin0:
  351. sbis PINB,0
  352. rjmp read_pin0
  353.  
  354. clr temp ; reset
  355. nop
  356.  
  357. read_pin1:
  358.  
  359. ;inc temp
  360. sbic PINB,0
  361. rjmp read_pin1 ;loop
  362.  
  363. ret
  364. ;***************************************************************************
  365. ;***************************************************************************
  366. hex2dec: ;convert hexa 2 ascii 2dgt (<99) 21-09-05
  367. push r16
  368. push r17
  369. push r18
  370. ldi r16,0x30
  371. ldi r17,0x30
  372. ldi r18,0x30
  373.  
  374. dec0: cpi temp,100
  375. brsh dec3
  376.  
  377. dec1: cpi temp,0x0A
  378. brsh dec2
  379. add r18,temp
  380. mov temp,r16
  381. rcall putchar
  382. mov temp,r17
  383. rcall putchar
  384. mov temp,r18
  385. rcall putchar
  386.  
  387. pop r18
  388. pop r17
  389. pop r16
  390.  
  391. ret
  392.  
  393. dec2: subi temp,0x0A
  394. inc r17
  395. rjmp dec1
  396.  
  397. dec3: subi temp,100
  398. inc r16
  399. rjmp dec0
  400. ;***************************************************************************
  401. _dispRam: ;5nov13
  402.  
  403. ldi ZH,high(ram_+16)
  404. ldi ZL,low(ram_+16)
  405. ldi r21,16
  406.  
  407. _dispRam1:
  408. ld temp,z+
  409. ;rcall hex2dec
  410. ldi r22,48
  411. add temp,r22
  412. rcall putchar
  413. dec r21
  414. brne _dispRam1
  415.  
  416.  
  417. ret
  418. ;***************************************************************************
  419. bits2hex: ; convert biner 8bits ke hexa 5nov13
  420. clr temp
  421. ldi ZH,high(ram_+16)
  422. ldi ZL,low(ram_+16)
  423. ldi r21,8
  424.  
  425. bits2hex_1:
  426. ld r0,z+
  427. add temp,r0
  428. lsl temp
  429. dec r21
  430. brne bits2hex_1
  431. rcall hex2dec
  432.  
  433. ret
  434. ;***************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment