;======================================================================= ;ram memory: ;-----------------------special register-------------------------------- indf equ 00h timer equ 01h ;8-bit real-time clock/counter pc equ 02h ;low 8-bit nibble of PC status equ 03h ;status register fsr equ 04h ;indirect data address pointer ra equ 05h ;ra port register rb equ 06h ;rb port register cmpcon equ 07h ;compare register ioca equ 05h ;ioca control register iocb equ 06h ;iocb control register pcon equ 0ah ;WDT a_wucon equ 0bh ;ra port pull high register b_wucon equ 0ch ;rb port pull high register ir_cycle equ 0dh ;IR cycle register ir_duty equ 0eh ;IR duty register ;-------------------------------------------------------------------- ;----------------------define register------------------------------- key_name equ 010h ;use look up table key_count equ 011h ;10*3ms=30ms wr0 equ 012h ;purpose register key_flag equ 013h ;press/release flag ;b0--->ra0 port release/press ;b1--->ra1 port release/press ;b2--->ra2 port release/press ;b3--->ra3 port release/press ;b4--->ra4 port release/press ;b5--->ra5 port release/press ;b6--->ra6 port release/press ;b7--->ra7 port release/press flag equ 014h ;send data flag flag_dis equ 015h ;use 32 bit rotate ir_flag equ 017h ;id code high nibble ir_flag1 equ 018h ;is code low nibble rf_data_h equ 019h ;key code high nibble rf_data_l equ 01ah ;key code low nibble ir_buf equ 01bh head_bu equ 021h ;-------------------------------------------------------------------- ;------------------------constant register--------------------------- ;==================================================================== ;--------------------programme begin--------------------------------- ;-------------------------------------------------------------------- ;rom memory: org 01ffh ;begin address from 1ffh lgoto reset org 000h ;memory begin from 000h ;==================================================================== ;-------------------------------------------------------------------- ;-----------------key table subroutine begin------------------------- ;-------------------------------------------------------------------- ;==================================================================== key_table_1: addar pc,1 ;result in pc register retia 00ch ;S1 Open/Close retia 010h ;S2 Power retia 011h ;S3 Key 1 retia 001h ;S4 Key 2 retia 004h ;S5 Key 3 retia 007h ;S6 Key 4 retia 00ah ;S7 Key 5 retia 00fh ;S8 Key 6 key_table_2: addar pc,1 retia 00dh ;S9 Key 7 retia 020h ;S10 Key 8 retia 021h ;S11 Key 9 retia 002h ;S12 +10 retia 005h ;S13 Key 0 retia 008h ;S14 T retia 000h ;S15 E.P.M. retia 01dh ;S16 E.A.M. key_table_3: addar pc,1 retia 02dh ;S17 Slow Left retia 03eh ;S18 Slow Right retia 03bh ;S19 Angle retia 003h ;S20 Subtitle retia 006h ;S21 Audio retia 009h ;S22 Pause/Step retia 033h ;S23 Play retia 035h ;S24 Stop key_table_4: addar pc,1 retia 00ch ;S25 Skip Left retia 03ah ;S26 REV retia 02ah ;S27 FWD retia 020h ;S28 kip Right retia 021h ;S29 Up retia 00dh ;S30 Down retia 00eh ;S31 Left retia 028h ;S32 Right key_table_5: addar pc,1 retia 035h ;S33 Enter retia 028h ;S34 Top Menu retia 031h ;S35 Menu retia 032h ;S36 Clear retia 029h ;S37 Display retia 034h ;S38 Navi retia 037h ;S39 Return retia 037h ;S40 Memory key_table_6: addar pc,1 retia 036h ;S41 Play Mode retia 036h ;S42 A-B Mode retia 0ffh ;S43 PBC retia 0ffh ;S44 Setup retia 0ffh ;S45 Progressive retia 0ffh ;S46 Zoom retia 0ffh ;S47 Store retia 0ffh ;S48 No use key_table_7: addar pc,1 retia 0ffh ;S49 Play Mode retia 0ffh ;S50 A-B Mode retia 0ffh ;S51 PBC retia 0ffh ;S52 Setup retia 0ffh ;S53 Progressive retia 0ffh ;S54 Zoom retia 0ffh ;S55 Store retia 0ffh ;S56 No use ;-------------------------------------------------------------------- ; consumer code table ;-------------------------------------------------------------------- head_table_1: addar pc,1 ;result in pc register retia 000h ;S1 Open/Close retia 000h ;S2 Power retia 000h ;S3 Key 1 retia 005h ;S4 Key 2 retia 005h ;S5 Key 3 retia 005h ;S6 Key 4 retia 005h ;S7 Key 5 retia 005h ;S8 Key 6 head_table_2: addar pc,1 retia 000h ;S9 Key 7 retia 000h ;S10 Key 8 retia 000h ;S11 Key 9 retia 005h ;S12 +10 retia 005h ;S13 Key 0 retia 005h ;S14 T retia 005h ;S15 E.P.M. retia 005h ;S16 E.A.M. head_table_3: addar pc,1 retia 005h ;S17 Slow Left retia 005h ;S18 Slow Right retia 005h ;S19 Angle retia 005h ;S20 Subtitle retia 005h ;S21 Audio retia 005h ;S22 Pause/Step retia 005h ;S23 Play retia 005h ;S24 Stop head_table_4: addar pc,1 retia 005h ;S25 Skip Left retia 005h ;S26 REV retia 005h ;S27 FWD retia 005h ;S28 kip Right retia 005h ;S29 Up retia 005h ;S30 Down retia 005h ;S31 Left retia 005h ;S32 Right head_table_5: addar pc,1 retia 005h ;S33 Enter retia 005h ;S34 Top Menu retia 005h ;S35 Menu retia 005h ;S36 Clear retia 005h ;S37 Display retia 005h ;S38 Navi retia 005h ;S39 Return retia 005h ;S40 Memory head_table_6: addar pc,1 retia 005h ;S41 Enter retia 005h ;S42 Top Menu retia 005h ;S43 Menu retia 005h ;S44 Clear retia 005h ;S45 Display retia 005h ;S46 Navi retia 005h ;S47 Return retia 005h ;S48 Memory head_table_7: addar pc,1 retia 005h ;S49 Enter retia 005h ;S50 Top Menu retia 005h ;S51 Menu retia 005h ;S52 Clear retia 005h ;S53 Display retia 005h ;S54 Navi retia 005h ;S55 Return retia 005h ;S56 Memory ;-------------------------------------------------------------------- ;-------------------key table subroutine end------------------------- ;-------------------------------------------------------------------- ;==================================================================== ;-------------------------------------------------------------------- ;-------------------key scan subroutine begin------------------------ ;-------------------------------------------------------------------- ;==================================================================== low_b1: movia 0fch ;b1 output low,other as input iost iocb bcr rb,1 lgoto low_re low_b2: movia 0fah ;b2 output low,other as input iost iocb bcr rb,2 lgoto low_re low_b3: movia 0f6h ;b3 output low,other as input iost iocb bcr rb,3 lgoto low_re low_b4: movia 0eeh ;b4 output low,other as input iost iocb bcr rb,4 lgoto low_re low_b5: movia 0deh ;b5 output low,other as input iost iocb bcr rb,5 lgoto low_re low_b6: movia 0beh ;b6 output low,other as input iost iocb bcr rb,6 lgoto low_re low_b7: movia 07eh iost iocb bcr rb,7 nop nop low_re: ;bcr rb,0 return ;------------------------------------------------------------ key_scan: lcall low_b1 movr ra,0 ;read ra port in acc xoria 0ffh btrsc status,2 ;ra=0ff? lgoto key_scan_1 ;find next keyname if ra=0ffh lcall find_key ;find keyname if ra/=0ffh movr key_name,0 ;------- lcall head_table_1 movar ir_flag movr key_name,0 ;------- lcall key_table_1 ;look up key table 1 lgoto key_scan_exit ;---------------------------------------------- key_scan_1: lcall low_b2 movr ra,0 ;read ra port in acc xoria 0ffh btrsc status,2 ;ra=0ffh? lgoto key_scan_2 ;find next keyname if ra=0ffh lcall find_key movr key_name,0 ;------- lcall head_table_2 movar ir_flag movr key_name,0 ;------- lcall key_table_2 ;look up key table 2 lgoto key_scan_exit ;---------------------------------------------- key_scan_2: lcall low_b3 movr ra,0 ;read ra port in acc xoria 0ffh btrsc status,2 ;ra=0ffh? lgoto key_scan_3 ;find next keyname if ra=0ffh lcall find_key ;find keyname movr key_name,0 ;------- lcall head_table_3 movar ir_flag movr key_name,0 ;------- lcall key_table_3 ;look-up key table 3 lgoto key_scan_exit ;---------------------------------------------- key_scan_3: lcall low_b4 movr ra,0 ;read ra port in acc xoria 0ffh btrsc status,2 ;ra=0ffh? lgoto key_scan_4 ;find next keyname if ra=0ffh lcall find_key ;find keyname if ra/=0ffh movr key_name,0 ;------- lcall head_table_4 movar ir_flag movr key_name,0 ;------- lcall key_table_4 ;look up key table 4 lgoto key_scan_exit ;----------------------------------------------- key_scan_4: lcall low_b5 movr ra,0 xoria 0ffh ;ra=0ffh? btrsc status,2 lgoto key_scan_5 ;find next keyname if ra=0ffh lcall find_key movr key_name,0 ;------- lcall head_table_5 movar ir_flag movr key_name,0 ;------- lcall key_table_5 ;look up key table 5 lgoto key_scan_exit ;----------------------------------------------- key_scan_5: lcall low_b6 movr ra,0 xoria 0ffh ;ra=0ffh? btrsc status,2 lgoto key_scan_6 ;find next keyname if ra=0ffh lcall find_key movr key_name,0 ;------- lcall head_table_6 movar ir_flag movr key_name,0 ;------- lcall key_table_6 ;look up key table 6 lgoto key_scan_exit ;----------------------------------------------- key_scan_6: lcall low_b7 movr ra,0 xoria 0ffh btrsc status,2 lgoto key_scan_end lcall find_key movr key_name,0 ;------- lcall head_table_7 movar ir_flag movr key_name,0 ;------- lcall key_table_7 ;------------------------------------------------ key_scan_exit: movar rf_data_h ;key code in rf_data_h movar rf_data_l ;key com code in rf_data_l return key_scan_end: clrr flag return ; lgoto sleep_mode ;go sleep mode ;-------------------confirm key name subroutine----------------------- find_key: btrsc ra,0 ;ra0 is low? lgoto key_loop_1 ; return ;end if key not release movia 0e3h movar wr0 ;delay 3ms--->227*3*4.4us=3ms key_a0: decrsz wr0,1 lgoto key_a0 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto find_key bsr flag,0 ;key is press--->rf first send flag clrr key_name ;key_name=0 lgoto key_loop_end key_loop_1: ;--------------find key of ra1 row----------- key_wait_1: btrsc ra,1 ;read ra.1 port status lgoto key_loop_2 ; return movia 0e3h movar wr0 ;delay 3ms key_a1: decrsz wr0,1 lgoto key_a1 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto key_wait_1 bsr flag,0 movia 01h ;key_name=1 movar key_name ;clrr key_name lgoto key_loop_end key_loop_2: ;-------------find key of ra2 row-------------- key_wait_2: btrsc ra,2 lgoto key_loop_3 ; return movia 0e3h movar wr0 ;delay 3ms key_a2: decrsz wr0,1 lgoto key_a2 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto key_wait_2 bsr flag,0 movia 02h ;key_name=2 movar key_name lgoto key_loop_end key_loop_3: ;----------------find key of ra3 row--------------- key_wait_3: btrsc ra,3 lgoto key_loop_4 ; return movia 0e3h movar wr0 ;delay 3ms key_a3: decrsz wr0,1 lgoto key_a3 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto key_wait_3 bsr flag,0 movia 03h ;key_name=3 movar key_name lgoto key_loop_end key_loop_4: ;---------------find key of ra4 row---------------- key_wait_4: btrsc ra,4 lgoto key_loop_5 ; return movia 0e3h movar wr0 ;delay 3ms key_a4: decrsz wr0,1 lgoto key_a4 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto key_wait_4 bsr flag,0 movia 04h ;key_name=4 movar key_name lgoto key_loop_end key_loop_5: ;-------------find key of ra5 row-------------- key_wait_5: btrsc ra,5 lgoto key_loop_6 ; return movia 0e3h movar wr0 ;delay 3ms key_a5: decrsz wr0,1 lgoto key_a5 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto key_wait_5 bsr flag,0 movia 05h ;key_name=5 movar key_name lgoto key_loop_end key_loop_6: ;--------------find key of ra6 row------------- key_wait_6: btrsc ra,6 lgoto key_loop_7 movia 0e3h movar wr0 ;delay 3ms key_a6: decrsz wr0,1 lgoto key_a6 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto key_wait_6 bsr flag,0 movia 06h ;key_name=6 movar key_name lgoto key_loop_end key_loop_7: ;--------------find key of ra7 row------------ key_wait_7: btrsc ra,7 lgoto key_loop_over movia 0e3h movar wr0 ;delay 3ms key_a7: decrsz wr0,1 lgoto key_a7 decrsz key_count,1 ;delay 10*3ms=30ms reach? lgoto key_wait_7 bsr flag,0 movia 07h ;key_name=7 movar key_name lgoto key_loop_end key_loop_over: clrr flag ;-----------find all key end-------------- key_loop_end: movia 05h movar key_count return ;==================================================================== ;-------------------------------------------------------------------- ;--------------------key scan subroutine end------------------------- ;-------------------------------------------------------------------- ;==================================================================== ;==================================================================== ;-------------------------------------------------------------------- ;--------------------ir send subroutine begin------------------------ ;-------------------------------------------------------------------- ;==================================================================== data_one: movia 021h ;00100001b ;disable IRout&LVDT iost pcon ;send ir low 840us ;-------------- ;delay 840us data_one_10: movia 03ch ;(60*3+3)*4.4us=840us movar wr0 data_one_11: decrsz wr0,1 lgoto data_one_11 ;-------------- ;send 38khz 840us movia 025h ;00100101b ;open 38khz iost pcon ;enable ir ;-------------- ;delay 840us data_one_20: movia 03ch ;(60*3+3)*4.4us=840us movar wr0 data_one_21: decrsz wr0,1 lgoto data_one_21 return ;-------------------------------------------------------- data_zero: movia 025h ;disable IRout&LVDT iost pcon ;send ir low 840us ;-------------- ;delay 840us data_zero_10: movia 03ch ;(60*3+3)*4.4us=840us movar wr0 data_zero_11: decrsz wr0,1 lgoto data_zero_11 ;-------------- ;send 38khz 840us movia 021h ;open 38khz iost pcon ;enable ir ;-------------- ;delay 840us data_zero_20: movia 03ch ;(60*3+3)*4.4us=840us movar wr0 data_zero_21: decrsz wr0,1 lgoto data_zero_21 return ;-------------------------------------------------------- rf_sub: movia 00h ;rb as output and output low iost iocb movr ir_flag,0 movar head_bu ;movia 00h ;movar rb ;bcr rb,0 clrr timer ;clear timer register for 108ms btrsc flag,0 ;key is press? lgoto rf_sub1 return ;-------------------------------------- ;send head code rf_sub1: clrr flag btrsc flag_dis,0 goto ir_head_11 ;------- ir_head_10: ;110 lcall data_one lcall data_one lcall data_zero lgoto ir_start_1 ir_head_11: ;111 lcall data_one lcall data_one lcall data_one ;-------------------------------------- ;send consumer code ir_start_1: movr head_bu,0 movar ir_flag movia 05h movar ir_buf ir_start1: btrss ir_flag,4 lgoto ir_start1_1 lcall data_one bsr status,0 lgoto ir_start1_end ir_start1_1: lcall data_zero bcr status,0 ir_start1_end: rlr ir_flag,1 decrsz ir_buf,1 lgoto ir_start1 ;-------------------------------------- ;send data code clrr ir_flag movia 06h movar ir_buf ir_start2: btrss rf_data_h,5 lgoto ir_start2_1 lcall data_one bsr status,0 lgoto ir_start2_end ir_start2_1: lcall data_zero bcr status,0 ir_start2_end: rlr rf_data_h,1 decrsz ir_buf,1 goto ir_start2 ;---------------------------------------------- movr rf_data_l,0 movar rf_data_h movia 021h iost pcon ir_code_loop: movr ra,0 xoria 0ffh btrss status,2 lgoto ir_repeat clrr flag return ir_repeat: movr timer,0 xoria 060h ;1/455k*2*256*96=85.4ms btrss status,2 lgoto ir_repeat clrr timer lgoto rf_sub1 ;-------------------------------------------------------------------- ;---------------------ir send subroutine end------------------------- ;==================================================================== ;==================================================================== ;------------------initial ram subroutine begin---------------------- ;-------------------------------------------------------------------- initial_ram: movia 020h ;disable WDT,IROUT,enable LVDT iost pcon movia 00h movar indf ;clear indf register movar timer ;clear value of timer movar fsr ;clear fsr register movar status ;clear status register movia 0ffh ;pa port as input iost ioca movia 0ffh movar ra movia 00h ;pb port as output iost iocb movia 00h movar rb iost b_wucon movia 047h ;timer prescaler=256 option ;timer clock source is internal instruction clock cycle movia 0ch ;IR cycle=12 iost ir_cycle movia 04h ;IR duty=4 iost ir_duty return ;==================================================================== ;----------------initial data subroutine begin----------------------- ;==================================================================== initial_data: movia 00h movar flag ;defautlt flag=00h movar key_name ;default key_name=00h movia 05h ;key scan count=10*3ms=30ms movar key_count return ;-------------------------------------------------------------------- ;----------------initial data subroutine begin----------------------- ;-------------------------------------------------------------------- ;==================================================================== ;==================================================================== ;==================================================================== reset: lcall initial_ram ;initial special register lcall initial_data ;initial random data ;-------------------------------------- ;-------------------------------------- sleep_mode: movia 01h xorar flag_dis,1 movia 0ffh iost ioca ;pa as input movia 0ffh iost a_wucon ;ra can wake-up sleep mode movia 00h iost iocb ;rb as output nop ;movia 00h ;movar rb ;rb output low bsr rb,0 nop nop movr ra,1 ;read ra port and result in ra register sleep nop nop halt_mode: lcall key_scan ;key scan subroutine lcall rf_sub ;rf send subroutine lgoto sleep_mode ;==================================================================== ;==================================================================== ;====================================================================