Cám ơn anh Dũng.
To Kilo: Download đc bạn ah! Xem lại - coi chừng máy bị nhiễm Virrus không cho Down.
To Kilo: Download đc bạn ah! Xem lại - coi chừng máy bị nhiễm Virrus không cho Down.
;========================================================================================= ;THU VIEN ========================================================================== ;========================================================================================= .include "m8515def.inc" .include "Quangbao.inc" ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** .equ time_on = 0x01fa .equ time_off = 0x01fd .equ _time_on = 0 .equ _time_off = 1 ;========================================================================================= ;DAT TEN BIEN THANH VIEN ========================================================== ;========================================================================================= .def m_vi_tri_load_data = r15 .def m_vi_tri_hang = r14 .def m_vi_tri_rot_low = r13 .def m_vi_tri_rot_high = r12 .def m_kieu_chay = r11 .def m_mode_chay_begin = r10 .def m_mode_chay_end = r9 .def m_cursel_high = r8 .def m_cursel_low = r7 .def m_mode_chay_center = r6 .def m_time_on_off = r5 ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;DAT TEN BIEN THANH VIEN ========================================================== ;========================================================================================= .def cursel_xanh_high = r25 .def cursel_xanh_low = r24 .def cursel_do_high = r23 .def cursel_do_low = r22 .def cursel_low = r21 .def cursel_high = r20 .def cursel_a = r19 .def cursel_b = r18 .def vi_tri_hang = r17 ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;DAT TEN POC XUAT THU ================================================================== ;========================================================================================= .equ chan_dk = 0x18 ;PORTB .equ cs = 0x12 ;PORTD .equ AT24 = 0x07 ;PORTE .equ AT24_D = 0x06 ;DDRE .equ AT24_P = 0x05 ;PINE .equ chan_do = 6 .equ chan_xanh = 7 .equ ck_led = 5 .equ en_led = 4 .equ en = 3 .equ cs_IC = 5 .equ data_24 = 0 .equ clock_24 = 2 ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CHINH ================================================================== ;========================================================================================= .cseg .org 0x0000 rjmp RESET .org 0x0006 rjmp DONG_HO .org 0x0009 rjmp THU_DATA .org 0x000b rjmp PHAT_DATA .org 0x0011 ;========================================================================================= ;CHUONG TRINH RESET ================================================================== ;========================================================================================= RESET: ldi r16,low(0x00ff) out SPL,r16 ;stac ldi r16,high(0x00ff) out SPH,r16 ;stac ;======================================================================== ldi r16,0b11111111 ;CAU HINH CHAN DIEU KHIEN XUAT PORTB out DDRB, r16 ;======================================================================== ldi r16,0b11111111 ;CAU HINH CHAN DIEU KHIEN XUAT PORTE out DDRE, r16 ;======================================================================== ldi r16,0b11101010 ;CAU HINH CHAN DIEU KHIEN PORTD out DDRD, r16 ;======================================================================== ldi r16,0b10000000 ;truy xuat RAN ngoai out MCUCR,r16 ;======================================================================== ;KHOI TAO TIME 0 ldi r16,5 out TCCR0,r16 ;CHAY TIME 0 VOI XUNG DONG HO /1024 ldi r16,-19 ;50X16 = 800Hz out TCNT0,r16 ;KHOI TAO TIME 1 ldi r16,5 out TCCR1B,r16 ;CHAY TIME 1 VOI XUNG DONG HO /1024 ldi r16,low(-62500) ;0.25Hz out TCNT1L,r16 ldi r16,high(-62500) ;0.25Hz out TCNT1H,r16 ldi r16,0x80 ;CHO PHEP NGAT TRAN TIME 1 out TIMSK,r16 ;KHOI TAO PORT NOI TIEP ldi r16,low(103) ;9600 0 8 1 out UBRRL, r16 ldi r16,high(103) out UBRRH, r16 ldi r16, 0b11011000 ;RXCIE.7 = 1 ngat thu, TXCIE.6 = 1 ngat phat, RXEN:.4 = 1 cho nhan, TXEN.3 = 1 cho phat out UCSRB,r16 ;======================================================================== clr m_time_on_off ;mac dinh la khong co hen gio start_on: sbi cs,en ;tat power wdr sbrc m_time_on_off,_time_on rjmp start_on nop rcall start_QB ;======================================================================== sei ;CHO PHEP TOAN BO NGAT HOAT DONG ;---------------------- main: wdr ;reset watchdog sbrc m_time_on_off,_time_off rjmp start_on in r16,TIFR sbrs r16,TOV0 rjmp main ldi r16,(1<<TOV0) out TIFR,r16 ; Clear TOV0/ clear pending interrupts lds r16,Frame_RXD inc r16 sts Frame_RXD,r16 cpi r16,10 brlo not_Oncom_temp ldi r16,0 ;lon hon bang 2 sts Frame_RXD,r16 ;reset Frame_RXD lds r17,point_RXD sts point_RXD,r16 ;reset point TXD cpi r17,0 breq bao_connect cpi r17,4 brne not_mode_PC4 ldi YL,low(vung_data_RXD) ldi YH,high(vung_data_RXD) ld r16,Y+ mov r17,r16 ld r18,Y+ add r17,r18 ld r19,Y+ add r17,r19 ld r16,Y cp r17,r16 ;text loi brne not_Oncom_temp ;bi loi cpi r18,ID_QuangBao ;text ID brne not_Oncom_temp ;biloi cpi r19,CONNECT_PC ;text CONNECT_PC brne not_CONNECT_PC rcall connect_to_PC rjmp not_Oncom ;================================= bao_connect: ldi r16,ID_QuangBao out UDR,r16 not_Oncom_temp: rjmp not_Oncom ;------------------------------------- not_CONNECT_PC: cpi r19,START_PC ;text START brne not_START_PC rcall start_QB rjmp not_Oncom ;------------------------------------- not_START_PC: cpi r19,EEPROM_FILE ;text EEPROM_FILE brne not_EEPROM_FILE lds r16,type_FILE cp r16,r19 breq recivered_temp ;neu lap lai bo qua sts type_FILE,r19 rcall load_receiving_data ldi r16,0xff sts cursel_FILEH,r16 sts cursel_FILEL,r16 recivered_temp: rjmp recivered ;------------------------------------- not_EEPROM_FILE: cpi r19,AT24_FILE ;text AT24_FILE brne not_AT24_FILE lds r16,type_FILE cp r16,r19 breq recivered ;neu lap lai bo qua sts type_FILE,r19 ldi r16,0xff sts cursel_FILEH,r16 sts cursel_FILEL,r16 rjmp recivered ;------------------------------------- not_AT24_FILE: rjmp not_Oncom ;============================================== not_mode_PC4: cpi r17,10 brne not_mode_PC10 ldi YL,low(vung_data_RXD) ldi YH,high(vung_data_RXD) ld r16,Y+ mov r17,r16 ld r18,Y+ add r17,r18 ld r19,Y+ add r17,r19 ld r16,Y+ cp r17,r16 brne not_Oncom cpi r18,ID_QuangBao brne not_Oncom cpi r19,TIME_PC brne not_TIME_PC rcall set_Time_PC rjmp not_Oncom ;----------------------------- not_TIME_PC: cpi r19,TIME_SET brne not_Oncom rcall set_Time_ONOFF rjmp not_Oncom ;============================================== not_mode_PC10: cpi r17,67 brne not_mode_PC67 ldi YL,low(vung_data_RXD) ldi YH,high(vung_data_RXD) ld cursel_high,Y+ ld cursel_low,Y lds r16,cursel_FILEH cp r16,cursel_high brne new_cursel lds r16,cursel_FILEL cp r16,cursel_low brne new_cursel rjmp recivered new_cursel: rcall text_loi_TX cpi r16,0 brne not_Oncom sts cursel_FILEH,cursel_high sts cursel_FILEL,cursel_low rcall ghi_file recivered: ldi r16,ENABLE_RECIVER out UDR,r16 rjmp not_Oncom ;============================================== not_mode_PC67: not_Oncom: ;========================================================================================= ;CHUONG TRINH NGAT QUET MA TRAN LED ================================================== ;========================================================================================= ldi r16,-19 out TCNT0,r16 ;NAP LAI GIA TRI TIME sbi cs,en ;tat power cbi chan_dk,en_led sbi chan_dk,en_led ;chot data led out chan_dk,m_vi_tri_hang cbi cs,en ;mo power rcall dieu_khien_hang rcall dich_data_led rjmp main ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** Turn_on_WDT: wdr ldi r16,0x18 ;enable watchdog out WDTCR,r16 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** Turn_off_WDT: ; Write logical one to WDCE and WDE ldi r16, (1<<WDCE)|(1<<WDE) out WDTCR, r16 ; Turn off WDT ldi r16, (0<<WDE) out WDTCR, r16 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** start_QB: sbi cs,en ;tat power rcall Turn_off_WDT ldi r16,0 out TCCR0,r16 ;TAT TIME 0 sbi cs,6 sbi cs,7 sbi cs,cs_IC ldi r16,0 sts point_RXD,r16 sts point_TXD,r16 sts Frame_RXD,r16 ;Time ngat RXD sts type_FILE,r16 ///////////////////////////////////////////////////////////////////////// clr m_vi_tri_load_data ;vi_tri_load_data = 0; clr m_vi_tri_hang ;m_vi_tri_hang = 0 clr m_cursel_high ;m_cursel = 0 clr m_cursel_low ;m_cursel = 0 clr m_kieu_chay ;m_kieu_chay = 0 clr m_mode_chay_begin ;m_mode_chay = 0 clr m_mode_chay_end ;m_mode_chay = 0 clr m_mode_chay_center ldi XH,high(0x0184) ldi XL,low(0x0184) rcall read_byte cpi r16,0xff breq chua_co_data rcall load_table rcall load_data_hien_thi ret chua_co_data: rcall load_no_data ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** text_loi_TX: ldi YL,low(vung_data_RXD) ldi YH,high(vung_data_RXD) ld r16,Y+ ld r16,Y+ ld r17,Y+ lap_text_loi_TX: ld r16,Y+ add r17,r16 cpi YL,66 brne lap_text_loi_TX ld r18,Y ldi r16,0xff cp r17,r18 brne loi_TX ldi r16,0 loi_TX: ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ghi_file: sbi cs,en ;tat power rcall Turn_off_WDT ldi r16,0 out TCCR0,r16 ;TAT TIME 0 ldi YL,low(vung_data_RXD) ldi YH,high(vung_data_RXD) ld cursel_high,Y+ ld cursel_low,Y+ lds r16,type_FILE cpi r16,AT24_FILE brne not_ghi_AT24_FILE rcall send_address lap_ghi_file_24: ld r16,Y+ rcall ghi_byte cpi YL,66 brne lap_ghi_file_24 rcall stop rjmp thoat_ghi_file ;--------------------------------------- not_ghi_AT24_FILE: mov XL,cursel_low mov XH,cursel_high lap_ghi_file_EEPROM: cpi XL,low(time_on) ldi r16,high(time_on) cpc XH,r16 brsh thoat_ghi_file ld r16,Y+ rcall write_byte cpi YL,66 brne lap_ghi_file_EEPROM thoat_ghi_file: ldi r16,5 out TCCR0,r16 ;CHAY TIME 0 VOI XUNG DONG HO /1024 rcall Turn_on_WDT ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** connect_to_PC: ldi r16,5 sts buffer_send,r16 ldi r16,1 sts point_TXD,r16 ldi YL,low(vung_data_TXD) ldi YH,high(vung_data_TXD) ldi r16,low(chieu_cao_bang) mov r17,r16 st Y+,r16 ldi r16,high(chieu_dai_bang) add r17,r16 st Y+,r16 ldi r16,low(chieu_dai_bang) add r17,r16 st Y+,r16 ldi r16,FORMAT_PC add r17,r16 st Y+,r16 st Y,r17 ldi r16,low(chieu_cao_bang) out UDR,r16 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** set_Time_PC: rcall set_dong_ho ldi r16,TIME_PC out UDR,r16 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** set_Time_ONOFF: sbi cs,en ;tat power rcall Turn_off_WDT ldi r16,0 out TCCR0,r16 ;TAT TIME 0 ldi XL,low(time_on) ldi XH,high(time_on) ld r16,Y+ sts offset_time_on,r16 rcall write_byte ld r16,Y+ sts offset_time_on+1,r16 rcall write_byte ld r16,Y+ sts offset_time_on+2,r16 rcall write_byte ld r16,Y+ sts offset_time_off,r16 rcall write_byte ld r16,Y+ sts offset_time_off+1,r16 rcall write_byte ld r16,Y+ sts offset_time_off+2,r16 rcall write_byte ldi r16,5 out TCCR0,r16 ;CHAY TIME 0 VOI XUNG DONG HO /1024 rcall Turn_on_WDT ldi r16,TIME_SET out UDR,r16 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON SET DONG HO ========================================================== ;========================================================================================= set_dong_ho: ld r18,Y+ ld r19,Y+ ld r20,Y+ ld r21,Y+ ld r22,Y+ ld r23,Y+ cbi cs,cs_IC ;select DS12887 ldi XH,high(vung_load_data) ldi XL,0x0b ;dia chi cua thanh ghi B ( DS12887) ldi r16,0x86 ;dung dong ho st X,r16 ldi XL,0x02 ;dia chi cua o nho phut ( DS12887) st X,r18 ldi XL,0x04 ;dia chi cua o nho gio ( DS12887) st X,r19 ldi XL,0x06 ;dia chi cua o nho thu ( DS12887) st X,r20 ldi XL,0x07 ;dia chi cua o nho ngay ( DS12887) st X,r21 ldi XL,0x08 ;dia chi cua o nho thang ( DS12887) st X,r22 ldi XL,0x09 ;dia chi cua o nho nam ( DS12887) st X,r23 ldi XL,0x0b ;dia chi cua thanh ghi B ( DS12887) ldi r16,0x06 ;chay dong ho st X,r16 ldi XL,0x0a ;dia chi cua thanh ghi A ( DS12887) ldi r16,0xaa ;chay dong ho st X,r16 sbi cs,cs_IC ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LOAD DONG HO ========================================================== ;========================================================================================= load_dong_ho: cbi cs,cs_IC ;select DS12887 ldi XH,high(vung_load_data) ldi XL,0x0a ;dia chi cua thanh ghi A ( DS12887) tro_doc_DS12887: ld r16,X sbrc r16,7 rjmp tro_doc_DS12887;neu r16.7 = 1 ldi XL,0x02 ;dia chi cua o nho phut ( DS12887) ld r18,X ldi XL,0x04 ;dia chi cua o nho gio ( DS12887) ld r19,X ldi XL,0x06 ;dia chi cua o nho thu ( DS12887) ld r20,X ldi XL,0x07 ;dia chi cua o nho ngay ( DS12887) ld r21,X ldi XL,0x08 ;dia chi cua o nho thang ( DS12887) ld r22,X ldi XL,0x09 ;dia chi cua o nho nam ( DS12887) ld r23,X sbi cs,cs_IC sts DS_TimePhut,r18 sts DS_TimeGio,r19 sts DS_TimeThu,r20 sts DS_TimeNgay,r21 sts DS_TimeThang,r22 sts DS_TimeNam,r23 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LOAD TABLE ========================================================== ;========================================================================================= load_table: ldi YL,low(tra_bang_color) ldi YH,high(tra_bang_color) ldi XL,0 ldi XH,0 lap_load_bang_color: rcall read_byte st Y+,r16 cpi XL,low(0x200) brne lap_load_bang_color cpi XH,high(0x200) brne lap_load_bang_color lds cursel_high,offset_font ;lay diem doc bang Font lds cursel_low,offset_font+1 ldi YL,low(tra_bang_font) ldi YH,high(tra_bang_font) rcall send_address rcall start ldi r16,0xa1 ;lenh doc RAM rcall ghi_byte lap_load_bang_font: rcall doc_byte st Y+,r16 cpi YL,low(tra_bang_logo) brne tiep_load_bang_font cpi YH,high(tra_bang_logo) brne tiep_load_bang_font rcall NAK rcall stop rjmp load_bang_logo tiep_load_bang_font: rcall ACK rjmp lap_load_bang_font load_bang_logo: lds cursel_high,offset_logo ;lay diem doc bang Logo lds cursel_low,offset_logo+1 ldi YL,low(tra_bang_logo) ldi YH,high(tra_bang_logo) rcall send_address rcall start ldi r16,0xa1 ;lenh doc RAM rcall ghi_byte lap_load_bang_logo: rcall doc_byte st Y+,r16 cpi YL,low(vung_data_RXD) brne tiep_load_bang_logo cpi YH,high(vung_data_RXD) brne tiep_load_bang_logo rcall NAK rcall stop ret tiep_load_bang_logo: rcall ACK rjmp lap_load_bang_logo ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH NGAT DONG HO ============================================================== ;========================================================================================= DONG_HO: in r2,SREG push r16 push r17 push XL push XH ldi r16,low(-62500) ;0.25Hz out TCNT1L,r16 ldi r16,high(-62500) ;0.25Hz out TCNT1H,r16 cbi cs,cs_IC ;select DS12887 ldi XH,high(vung_load_data) ldi XL,0x0a ;dia chi cua thanh ghi A ( DS12887) tro_doc_DS12887n: ld r16,X sbrc r16,7 rjmp tro_doc_DS12887n;neu r16.7 = 1 ldi XL,0x02 ;dia chi cua o nho phut ( DS12887) ld r16,X ldi XL,0x04 ;dia chi cua o nho gio ( DS12887) ld r17,X sbi cs,cs_IC lds XL,offset_time_off cpi XL,0 breq not_time_off lds XL,offset_time_off+1 lds XH,offset_time_off+2 cp r16,XL brne not_time_off cp r17,XH brne not_time_off ldi XL,0xff mov m_time_on_off,XL not_time_off: lds XL,offset_time_on cpi XL,0 breq not_time_on lds XL,offset_time_on+1 lds XH,offset_time_on+2 cp r16,XL brne not_time_on cp r17,XH brne not_time_on clr m_time_on_off not_time_on: pop XH pop XL pop r17 pop r16 out SREG,r2 reti ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH NGAT THU DATA ============================================================== ;========================================================================================= THU_DATA: in r3,SREG push r16 push r17 push YL push YH in r16,UDR lds YL,point_RXD ldi YH,0 subi YL,low(-vung_data_RXD) sbci YH,high(-vung_data_RXD) st Y,r16 ;nap bo dem lds r17,point_RXD inc r17 sts point_RXD,r17 ;cat con tro ldi r16,0 sts Frame_RXD,r16 pop YH pop YL pop r17 pop r16 out SREG,r3 reti ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH NGAT PHAT DATA ========================================================== ;========================================================================================= PHAT_DATA: in r4,SREG push r16 push r17 push YL push YH lds YL,point_TXD cpi YL,0 breq EXIT_PHAT_DATA ldi YH,0 subi YL,low(-vung_data_TXD) sbci YH,high(-vung_data_TXD) ld r16,Y out UDR,r16 lds r17,point_TXD inc r17 lds r16,buffer_send cp r16,r17 brne not_Onsend ldi r17,0 ;reset point_TXD not_Onsend: sts point_TXD,r17 ;cat con tro EXIT_PHAT_DATA: ldi r16,0 sts Frame_RXD,r16 pop YH pop YL pop r17 pop r16 out SREG,r4 reti ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LOAD DATA HIEN THI ================================================== ;========================================================================================= load_data_hien_thi: sbi cs,en ;tat power rcall Turn_off_WDT ldi r16,0 out TCCR0,r16 ;TAT TIME 0 rcall load_data_file inc m_vi_tri_load_data mov r16,m_vi_tri_load_data lds r17,tong_file cp r16,r17 brne set_mode_chay_auto ldi r16,2 ;neu het file mov m_vi_tri_load_data,r16 set_mode_chay_auto: rcall thay_mode_auto ldi r16,5 out TCCR0,r16 ;CHAY TIME 0 VOI XUNG DONG HO /1024 rcall Turn_on_WDT ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON THAY MODE CHAY ====================================================== ;========================================================================================= thay_mode_auto: cpi cursel_a,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_b,r16 brlo ma_hien_thi_nho_hon_cdb ldi r16,Kieu_SizeMax ;ma_hien_thi_lon hon_cdb mov m_kieu_chay,r16 subi cursel_a,low(-chieu_dai_bang) sbci cursel_b,high(-chieu_dai_bang) mov m_vi_tri_rot_low,cursel_a mov m_vi_tri_rot_high,cursel_b rjmp thoat_thay_mode ma_hien_thi_nho_hon_cdb: inc m_mode_chay_begin mov r16,m_mode_chay_begin cpi r16,tong_mode_chay_begin ;so sanh tong kieu chay brne thay_mode_chay_center clr m_mode_chay_begin thay_mode_chay_center: inc m_mode_chay_center mov r16,m_mode_chay_center cpi r16,tong_mode_chay_center ;so sanh tong kieu chay brne thay_mode_chay_end clr m_mode_chay_center thay_mode_chay_end: inc m_mode_chay_end mov r16,m_mode_chay_end cpi r16,tong_mode_chay_end ;so sanh tong kieu chay brne thoat_thay_mode clr m_mode_chay_end thoat_thay_mode: ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON DOI LICH ====================================================== ;========================================================================================= doi_lich: cpi r16,TimePhut brne not_TimePhut lds r16,DS_TimePhut ldi r17,0 rcall doi_BCD st X+,r16 st X+,r18 ret ;----------------------------- not_TimePhut: cpi r16,TimeGio brne not_TimeGio lds r16,DS_TimeGio ldi r17,0 rcall doi_BCD st X+,r16 st X+,r18 ret ;----------------------------- not_TimeGio: cpi r16,TimeNgay brne not_TimeNgay lds r16,DS_TimeNgay ldi r17,0 rcall doi_BCD st X+,r16 st X+,r18 ret ;----------------------------- not_TimeNgay: cpi r16,TimeThang brne not_TimeThang lds r16,DS_TimeThang ldi r17,0 rcall doi_BCD st X+,r16 st X+,r18 ret ;----------------------------- not_TimeThang: cpi r16,TimeNam brne not_TimeNam lds r16,DS_TimeNam ldi r17,0 rcall doi_BCD st X+,r16 st X+,r18 not_TimeThu: ret ;----------------------------- not_TimeNam: cpi r16,TimeThu brne not_TimeThu lds r16,DS_TimeThu cpi r16,2 brsh not_chu_nhat ldi ZH,high(Chu_nhat*2) ;vi tri cao cua ky tu ldi ZL,low(Chu_nhat*2) ;vi tr thap cua ky tu rjmp lap_load_data_thu not_chu_nhat: ldi ZH,high(Thu*2) ;vi tri cao cua ky tu ldi ZL,low(Thu*2) ;vi tr thap cua ky tu lap_load_data_thu: lpm r17,Z+ st X+,r17 cpi r17,' ' brne lap_load_data_thu cpi r16,2 brne not_thu_hai ldi ZH,high(hai*2) ;vi tri cao cua ky tu ldi ZL,low(hai*2) ;vi tr thap cua ky tu rjmp data_thu ;------------------------------------------ not_thu_hai: cpi r16,3 brne not_thu_ba ldi ZH,high(ba*2) ;vi tri cao cua ky tu ldi ZL,low(ba*2) ;vi tr thap cua ky tu rjmp data_thu ;------------------------------------------ not_thu_ba: cpi r16,4 brne not_thu_tu ldi ZH,high(tu*2) ;vi tri cao cua ky tu ldi ZL,low(tu*2) ;vi tr thap cua ky tu rjmp data_thu ;------------------------------------------ not_thu_tu: cpi r16,5 brne not_thu_nam ldi ZH,high(nam*2) ;vi tri cao cua ky tu ldi ZL,low(nam*2) ;vi tr thap cua ky tu rjmp data_thu ;------------------------------------------ not_thu_nam: cpi r16,6 brne not_thu_sau ldi ZH,high(sau*2) ;vi tri cao cua ky tu ldi ZL,low(sau*2) ;vi tr thap cua ky tu rjmp data_thu ;------------------------------------------ not_thu_sau: cpi r16,7 brne data_thu ldi ZH,high(bay*2) ;vi tri cao cua ky tu ldi ZL,low(bay*2) ;vi tr thap cua ky tu data_thu: lpm r16,Z+ st X+,r16 cpi r16,' ' brne data_thu ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LOAD RECIVING DATA ====================================================== ;========================================================================================= load_receiving_data: ldi r16,Kieu_CANHBAO ;kieu chay canh bao mov m_kieu_chay,r16 ldi ZH,high(receiving_data*2) ;vi tri cao cua ky tu ldi ZL,low(receiving_data*2) ;vi tr thap cua ky tu rjmp load_data_wanning ;========================================================================================= ;CHUONG TRINH CON LOAD NO DATA ====================================================== ;========================================================================================= load_no_data: ldi r16,Kieu_CANHBAO ;kieu chay canh bao mov m_kieu_chay,r16 ldi ZH,high(no_data*2) ;vi tri cao cua ky tu ldi ZL,low(no_data*2) ;vi tr thap cua ky tu load_data_wanning: sbi cs,en ;tat power rcall Turn_off_WDT ldi r16,0 out TCCR0,r16 ;TAT TIME 0 rcall xoa_data lpm cursel_high,Z+ lpm cursel_low,Z+ ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,cursel_low sbc cursel_b,cursel_high lsr cursel_b ror cursel_a add cursel_low,cursel_a adc cursel_high,cursel_b lap_lay_ma_warning: ;neu lon hon thi khong can trung tam bang lpm r16,Z+ lpm r17,Z+ ldi YH,vung_xanh_low ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 ldi YH,vung_xanh_high ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r17 subi cursel_a,low(-1) sbci cursel_b,high(-1) cp cursel_a,cursel_low brne lap_lay_ma_warning cp cursel_b,cursel_high brne lap_lay_ma_warning ldi r16,5 out TCCR0,r16 ;CHAY TIME 0 VOI XUNG DONG HO /1024 rcall Turn_on_WDT ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LOAD DATA FILE ====================================================== ;========================================================================================= load_data_file: rcall load_dong_ho ldi YL,2 mov YH,m_vi_tri_load_data mul YH,YL mov YL,r0 mov YH,r1 subi YL,low(-offset_file) sbci YH,high(-offset_file) ld cursel_high,Y+ ;lay diem doc FILE ld cursel_low,Y ldi XH,high(vung_load_data) ldi XL,low(vung_load_data) rcall send_address rcall start ldi r16,0xa1 ;lenh doc RAM rcall ghi_byte lap_load_file: rcall doc_byte cpi r16,TimeNam brsh lonbangTimeNam lonTimePhut: st X+,r16 cpi r16,END_DATA brne tiep_load_file rcall NAK rcall stop rcall load_data ret lonbangTimeNam: cpi r16,0xfc ;Timephut= 0xfb brsh lonTimePhut rcall doi_lich tiep_load_file: rcall ACK rjmp lap_load_file ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON DVI ================================================================== ;========================================================================================= Div: ;so bi chia r16,r17 so chia r18 ket qua r16,r17 so du r18 ldi r25,0 lap_chia: inc r25 mul r18,r25 cp r0,r16 cpc r1,r17 brne not_bang_ket_qua ldi r18,0 ;so du = 0 mov r16,r25 ldi r17,0 ret not_bang_ket_qua: brlo lap_chia dec r25 mul r18,r25 sub r16,r0 sbc r17,r1 mov r18,r16 mov r16,r25 ldi r17,0 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON DOI BCD ============================================================== ;========================================================================================= doi_BCD: ldi r18,10 rcall Div ;so bi chia r19 so chia r16 ket qua r17 so du r16 ldi r17,0x30 add r16,r17 add r18,r17 ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON XOA DATA ============================================================== ;========================================================================================= xoa_data: ldi XH,vung_xanh_low ;xoa trang vung hien thi ldi XL,0 ldi r16,0xff lap_xoa_data: st X+,r16 cpi XH,0xff brne lap_xoa_data cpi XL,0xff brne lap_xoa_data ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LOAD DATA ============================================================== ;========================================================================================= load_data: ldi cursel_a,0 ldi cursel_b,0 rcall xoa_data rcall doi_kytu_thanh_ma cpi cursel_a,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_b,r16 brsh ma_hien_thi_lon_hon_cdb ldi cursel_low,low(chieu_dai_bang) ldi cursel_high,high(chieu_dai_bang) sub cursel_low,cursel_a sbc cursel_high,cursel_b lsr cursel_high ror cursel_low mov cursel_a,cursel_low mov cursel_b,cursel_high rcall xoa_data rcall doi_kytu_thanh_ma ma_hien_thi_lon_hon_cdb: ;neu lon hon thi khong can trung tam bang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON DOI KYTU THANH MA ====================================================== ;========================================================================================= doi_kytu_thanh_ma: ldi XH,high(vung_load_data) ldi XL,low(vung_load_data) doc_data: ld r16,X+ ;lay mot ky tu trong chuoi data cpi r16,END_DATA ;neu la ma ket thuc brne khac_ma_ket_thuc ret ;------------------------------- khac_ma_ket_thuc: cpi r16,NEW_COLOR brne not_chon_mau_sac rcall lay_ma_mau rjmp doc_data ;================================================ not_chon_mau_sac: cpi r16,NEW_FONT brne not_chon_font rcall lay_ma_font rjmp doc_data ;================================================ not_chon_font: cpi r16,NEW_LOGO brne not_chon_logo rcall lay_ma_logo rjmp doc_data ;================================================ not_chon_logo: cpi r16,' ' brne not_khoang_trang subi cursel_a,low(-4) sbci cursel_b,high(-4) rjmp doc_data ;================================================ not_khoang_trang: subi r16,'!' ;tru de tim ra ky so ldi r17,2 mul r16,r17 ; khoang canh 2 byte mov YL,r0 mov YH,r1 ;nap vung doc ma tai Y vung truy xuat Z subi YL,low(-bang_font) sbci YH,high(-bang_font) ;vung truy xuat Z bat dau tu bang font ld ZH,Y+ ld ZL,Y+ ld r22,Y+ ld r22,Y cp r22,ZL brlo nho_hon_ZL sub r22,ZL load_kytu: lsr R22 subi ZL,low(-bang_font) sbci ZH,high(-bang_font) ;vung truy xuat Z bat dau tu bang font rcall lay_ma_ky_tu rjmp doc_data nho_hon_ZL: mov r16,ZL sub r16,r22 mov r22,r16 rjmp load_kytu ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LAY MA FONT ========================================================== ;========================================================================================= lay_ma_mau: ld r16,X+ ldi r17,4 mul r16,r17 mov r24,r0 mov r25,r1 subi r24,low(-tra_bang_color) sbci r25,high(-tra_bang_color) ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LAY MA FONT ========================================================== ;========================================================================================= lay_ma_font: ld r16,X+ ;lay ky FONT ldi r17,2 mul r16,r17 mov YL,r0 ;doi thanh vung truy xuat mov YH,r1 subi YL,low(-tra_bang_font) sbci YH,high(-tra_bang_font) ;doi di toi bang ld cursel_high,Y+ ;lay diem doc FONT ld cursel_low,Y ldi YL,low(bang_font) ldi YH,high(bang_font) rcall send_address rcall start ldi r16,0xa1 ;lenh doc RAM rcall ghi_byte lap_load_font: rcall doc_byte st Y+,r16 cpi YL,0x00 brne tiep_load_font cpi YH,0x20 brne tiep_load_font rcall NAK rcall stop ret tiep_load_font: rcall ACK rjmp lap_load_font ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LAY MA LOGO ========================================================== ;========================================================================================= lay_ma_logo: ld r16,X+ ;lay ky LOGO ldi r17,2 mul r16,r17 mov YL,r0 ;doi thanh vung truy xuat mov YH,r1 subi YL,low(-tra_bang_logo) sbci YH,high(-tra_bang_logo) ;doi di toi bang ld cursel_high,Y+ ld cursel_low,Y+ ;lay diem doc logo rcall send_address rcall start ldi r16,0xa1 ;lenh doc RAM rcall ghi_byte rcall doc_byte mov r22,r16 ;do rong LOGO rcall ACK lap_lay_ma_lodo: rcall doc_byte ldi YH,vung_xanh_low ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 rcall ACK rcall doc_byte ldi YH,vung_xanh_high ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 rcall ACK rcall doc_byte ldi YH,vung_do_low ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 rcall ACK rcall doc_byte ldi YH,vung_do_high ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 subi cursel_a,low(-1) sbci cursel_b,high(-1) dec r22 ;giam do rong LOGO cpi r22,0 brne tiep_lay_ma_lodo rcall NAK rcall stop ret tiep_lay_ma_lodo: rcall ACK rjmp lap_lay_ma_lodo ;***************************************************************************************** ;HET CHUONG TRINH CON LAY MA LOGO ****************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LAY MA KY TU ========================================================== ;========================================================================================= lay_ma_ky_tu: lap_lay_ma_ky_tu: ld r20,Z+ ld r21,Z+ mov YL,r24 mov YH,r25 ld r16,Y or r16,r20 ldi YH,vung_xanh_low ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 mov YL,r24 mov YH,r25 ldd r16,Y+1 or r16,r21 ldi YH,vung_xanh_high ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 mov YL,r24 mov YH,r25 ldd r16,Y+2 or r16,r20 ldi YH,vung_do_low ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 mov YL,r24 mov YH,r25 ldd r16,Y+3 or r16,r21 ldi YH,vung_do_high ldi YL,0 add YL,cursel_a adc YH,cursel_b st Y,r16 subi cursel_a,low(-1) sbci cursel_b,high(-1) cpi r20,0xff brne text_do_rong_ky_tu cpi r21,0xff brne text_do_rong_ky_tu ret text_do_rong_ky_tu: dec r22 ;giam do rong ky tu cpi r22,0 brne lap_lay_ma_ky_tu ret ;***************************************************************************************** ;HET CHUONG TRINH CON LAY MA KY TU ************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON DIEU KHIEN HANG ================================================== ;========================================================================================= dieu_khien_hang: dec m_vi_tri_hang mov r16,m_vi_tri_hang cpi r16,0xff ;so sanh chieu cao bang brne thoat_dieu_khien_hang ldi r16,chieu_cao_bang dec r16 mov m_vi_tri_hang,r16 ;nap vi tri hang = 0 ;------------------------------------ ;mot lap bang led mov r16,m_kieu_chay cpi r16,Kieu_CANHBAO ;kieu chay canh bao breq thoat_dieu_khien_hang inc m_cursel_low mov r16,m_cursel_low cpi r16,0 brne not_tang_cursel_high inc m_cursel_high not_tang_cursel_high: mov r16,m_kieu_chay cpi r16,Kieu_SizeMax ;kieu SizeMax brne kieu_chay_center cp m_cursel_low,m_vi_tri_rot_low cpc m_cursel_high,m_vi_tri_rot_high brlo thoat_dieu_khien_hang clr m_cursel_high ;m_cursel = 0 clr m_cursel_low ;m_cursel = 0 clr m_vi_tri_rot_low clr m_vi_tri_rot_high rjmp thay_data_hien_thi ;----------------------------- kieu_chay_center: ;kieu chay binh thuong mov r16,m_cursel_low cpi r16,low(chieu_dai_bang) ;chieu_dai_bang ;so sanh chieu dai bang ldi r16,high(chieu_dai_bang) cpc m_cursel_high,r16 ;chieu_dai_bang ;so sanh chieu dai bang brlo thoat_dieu_khien_hang clr m_cursel_high ;m_cursel = 0 clr m_cursel_low ;m_cursel = 0 clr m_vi_tri_rot_low clr m_vi_tri_rot_high ;------------------------------------ inc m_kieu_chay mov r16,m_kieu_chay cpi r16,tong_kieu_chay ;so sanh tong kieu chay brne thoat_dieu_khien_hang thay_data_hien_thi: clr m_kieu_chay ;nap kieu chay = 0 ;------------------------------------ rcall load_data_hien_thi ;nap data moi thoat_dieu_khien_hang: ret ;***************************************************************************************** ;***************************************************************************************** ;*****************************************************************************************
;========================================================================================= ;CHUONG TRINH CON DICH DATA LED ========================================================== ;========================================================================================= dich_data_led: mov r16,m_kieu_chay cpi r16,Kieu_SizeMax brne not_kieu_chay_chu ldi ZH,high(kieu_chay_chu) ;vi tri cao cua ky tu ldi ZL,low(kieu_chay_chu) ;kieu chay binh thuong icall ret ;-------------------------------------- not_kieu_chay_chu: cpi r16,Kieu_CANHBAO ;hien thi trang thai canh bao brne not_kieu_wanning ldi ZH,high(bat_led) ;vi tri cao cua ky tu ldi ZL,low(bat_led) icall ret ;-------------------------------------- not_kieu_wanning: cpi r16,0 brne not_kieu_chay_begin mov r16,m_mode_chay_begin cpi r16,chay_long_ngang brne not_mode_chay_long_ngang_0 ldi ZH,high(kieu_long_ngang_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_long_ngang_begin) icall ret ;--------------------------------------- not_kieu_chay_begin: cpi r16,2 brne not_kieu_chay_end rjmp kieu_chay_end not_kieu_chay_end: mov r16,m_mode_chay_center cpi r16,chay_chop_tat brne not_chay_chop_tat ldi ZH,high(kieu_chop_tat) ;vi tri cao cua ky tu ldi ZL,low(kieu_chop_tat) icall ret not_chay_chop_tat: ldi ZH,high(bat_led) ;vi tri cao cua ky tu ldi ZL,low(bat_led) icall ret ;--------------------------------------- not_mode_chay_long_ngang_0: cpi r16,chay_trai_qua brne not_mode_chay_trai_qua_0 ldi ZH,high(kieu_trai_qua_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_trai_qua_begin) icall ret ;--------------------------------------- not_mode_chay_trai_qua_0: cpi r16,chay_phai_qua brne not_mode_chay_phai_qua_0 ldi ZH,high(kieu_phai_qua_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_phai_qua_begin) icall ret ;--------------------------------------- not_mode_chay_phai_qua_0: cpi r16,chay_che_trai_qua brne not_mode_chay_che_trai_qua_0 ldi ZH,high(kieu_che_trai_qua_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_trai_qua_begin) icall ret ;--------------------------------------- not_mode_chay_che_trai_qua_0: cpi r16,chay_che_phai_qua brne not_mode_chay_che_phai_qua_0 ldi ZH,high(kieu_che_phai_qua_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_phai_qua_begin) icall ret ;--------------------------------------- not_mode_chay_che_phai_qua_0: cpi r16,chay_long_doc brne not_mode_chay_long_doc_0 ldi ZH,high(kieu_long_doc_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_long_doc_begin) icall ret ;--------------------------------------- not_mode_chay_long_doc_0: cpi r16,chay_tren_xuong brne not_mode_chay_tren_xuong_0 ldi ZH,high(kieu_tren_xuong_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_tren_xuong_begin) icall ret ;--------------------------------------- not_mode_chay_tren_xuong_0: cpi r16,chay_duoi_len brne not_mode_chay_duoi_len_0 ldi ZH,high(kieu_duoi_len_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_duoi_len_begin) icall ret ;--------------------------------------- not_mode_chay_duoi_len_0: cpi r16,chay_che_tren_xuong brne not_mode_chay_che_tren_xuong_0 ldi ZH,high(kieu_che_tren_xuong_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_tren_xuong_begin) icall ret ;--------------------------------------- not_mode_chay_che_tren_xuong_0: cpi r16,chay_che_duoi_len brne not_mode_chay_che_duoi_len_0 ldi ZH,high(kieu_che_duoi_len_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_duoi_len_begin) icall ret ;--------------------------------------- not_mode_chay_che_duoi_len_0: cpi r16,chay_chia_doi_vao brne not_mode_chay_chia_doi_vao_0 ldi ZH,high(kieu_chia_doi_vao_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_chia_doi_vao_begin) icall ret ;--------------------------------------- not_mode_chay_chia_doi_vao_0: cpi r16,chay_chia_doi_ra brne not_mode_chay_chia_doi_ra_0 ldi ZH,high(kieu_chia_doi_ra_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_chia_doi_ra_begin) icall ret ;--------------------------------------- not_mode_chay_chia_doi_ra_0: cpi r16,chay_che_chia_doi_vao brne not_mode_chay_che_chia_doi_vao_0 ldi ZH,high(kieu_che_chia_doi_vao_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_chia_doi_vao_begin) icall ret ;--------------------------------------- not_mode_chay_che_chia_doi_vao_0: cpi r16,chay_che_chia_doi_ra brne not_mode_chay_che_chia_doi_ra_0 ldi ZH,high(kieu_che_chia_doi_ra_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_chia_doi_ra_begin) icall ret ;--------------------------------------- not_mode_chay_che_chia_doi_ra_0: cpi r16,chay_rot_xuong brne not_mode_chay_rot_xuong_0 ldi ZH,high(kieu_rot_xuong_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_rot_xuong_begin) icall ret ;--------------------------------------- not_mode_chay_rot_xuong_0: cpi r16,chay_rot_len brne not_mode_chay_rot_len_0 ldi ZH,high(kieu_rot_len_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_rot_len_begin) icall ret ;--------------------------------------- not_mode_chay_rot_len_0: cpi r16,chay_rot_phai_qua brne not_mode_chay_rot_phai_qua_0 ldi ZH,high(kieu_rot_phai_qua_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_rot_phai_qua_begin) icall ret ;--------------------------------------- not_mode_chay_rot_phai_qua_0: cpi r16,chay_dan_phai_vao brne not_mode_chay_dan_phai_vao_0 ldi ZH,high(kieu_dan_phai_vao_begin) ;vi tri cao cua ky tu ldi ZL,low(kieu_dan_phai_vao_begin) icall ret ;--------------------------------------- not_mode_chay_dan_phai_vao_0: ldi ZH,high(bat_led) ;vi tri cao cua ky tu ldi ZL,low(bat_led) icall ret ;===================================================kieu_dan_phai_vao_begin kieu_chay_end: mov r16,m_mode_chay_end cpi r16,chay_long_ngang brne not_mode_chay_long_ngang_2 ldi ZH,high(kieu_long_ngang_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_long_ngang_end) icall ret ;--------------------------------------- not_mode_chay_long_ngang_2: cpi r16,chay_trai_qua brne not_mode_chay_trai_qua_2 ldi ZH,high(kieu_trai_qua_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_trai_qua_end) icall ret ;--------------------------------------- not_mode_chay_trai_qua_2: cpi r16,chay_phai_qua brne not_mode_chay_phai_qua_2 ldi ZH,high(kieu_phai_qua_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_phai_qua_end) icall ret ;--------------------------------------- not_mode_chay_phai_qua_2: cpi r16,chay_che_trai_qua brne not_mode_chay_che_trai_qua_2 ldi ZH,high(kieu_che_trai_qua_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_trai_qua_end) icall ret ;--------------------------------------- not_mode_chay_che_trai_qua_2: cpi r16,chay_che_phai_qua brne not_mode_chay_che_phai_qua_2 ldi ZH,high(kieu_che_phai_qua_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_phai_qua_end) icall ret ;--------------------------------------- not_mode_chay_che_phai_qua_2: cpi r16,chay_long_doc brne not_mode_chay_long_doc_2 ldi ZH,high(kieu_long_doc_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_long_doc_end) icall ret ;--------------------------------------- not_mode_chay_long_doc_2: cpi r16,chay_tren_xuong brne not_mode_chay_tren_xuong_2 ldi ZH,high(kieu_tren_xuong_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_tren_xuong_end) icall ret ;--------------------------------------- not_mode_chay_tren_xuong_2: cpi r16,chay_duoi_len brne not_mode_chay_duoi_len_2 ldi ZH,high(kieu_duoi_len_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_duoi_len_end) icall ret ;--------------------------------------- not_mode_chay_duoi_len_2: cpi r16,chay_che_tren_xuong brne not_mode_chay_che_tren_xuong_2 ldi ZH,high(kieu_che_tren_xuong_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_tren_xuong_end) icall ret ;--------------------------------------- not_mode_chay_che_tren_xuong_2: cpi r16,chay_che_duoi_len brne not_mode_chay_che_duoi_len_2 ldi ZH,high(kieu_che_duoi_len_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_duoi_len_end) icall ret ;--------------------------------------- not_mode_chay_che_duoi_len_2: cpi r16,chay_chia_doi_vao brne not_mode_chay_chia_doi_vao_2 ldi ZH,high(kieu_chia_doi_vao_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_chia_doi_vao_end) icall ret ;--------------------------------------- not_mode_chay_chia_doi_vao_2: cpi r16,chay_chia_doi_ra brne not_mode_chay_chia_doi_ra_2 ldi ZH,high(kieu_chia_doi_ra_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_chia_doi_ra_end) icall ret ;--------------------------------------- not_mode_chay_chia_doi_ra_2: cpi r16,chay_che_chia_doi_vao brne not_mode_chay_che_chia_doi_vao_2 ldi ZH,high(kieu_che_chia_doi_vao_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_chia_doi_vao_end) icall ret ;--------------------------------------- not_mode_chay_che_chia_doi_vao_2: cpi r16,chay_che_chia_doi_ra brne not_mode_chay_che_chia_doi_ra_2 ldi ZH,high(kieu_che_chia_doi_ra_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_che_chia_doi_ra_end) icall ret ;--------------------------------------- not_mode_chay_che_chia_doi_ra_2: cpi r16,chay_rot_xuong brne not_mode_chay_rot_xuong_2 ldi ZH,high(kieu_rot_xuong_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_rot_xuong_end) icall ret ;--------------------------------------- not_mode_chay_rot_xuong_2: cpi r16,chay_rot_len brne not_mode_chay_rot_len_2 ldi ZH,high(kieu_rot_len_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_rot_len_end) icall ret ;--------------------------------------- not_mode_chay_rot_len_2: cpi r16,chay_dan_phai_vao brne not_mode_chay_dan_phai_vao_2 ldi ZH,high(kieu_dan_phai_vao_end) ;vi tri cao cua ky tu ldi ZL,low(kieu_dan_phai_vao_end) icall ret ;--------------------------------------- not_mode_chay_dan_phai_vao_2: ldi ZH,high(bat_led) ;vi tri cao cua ky tu ldi ZL,low(bat_led) icall ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON READ EEROM ============================================================== ;========================================================================================= read_byte: sbic EECR,EEWE rjmp read_byte out EEARH, XH out EEARL, XL cli sbi EECR,EERE ;lenh doc EEPROM adiw XL,1 in r16,EEDR sei ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON WRITE EEROM ============================================================== ;========================================================================================= write_byte: sbic EECR,EEWE rjmp write_byte out EEARH, XH out EEARL, XL out EEDR,r16 cli sbi EECR,EEMWE sbi EECR,EEWE adiw XL,1 sei ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON START 24 ============================================================== ;========================================================================================= start: rcall delay_1us sbi AT24,data_24 rcall delay_1us sbi AT24,clock_24 rcall delay_1us cbi AT24,data_24 rcall delay_1us cbi AT24,clock_24 rcall delay_1us ret ;========================================================================================= ;CHUONG TRINH CON STOP 24 ============================================================== ;========================================================================================= stop: rcall delay_1us cbi AT24,data_24 rcall delay_1us sbi AT24,clock_24 rcall delay_1us sbi AT24,data_24 rcall delay_1us ret ;========================================================================================= ;CHUONG TRINH CON WRITE 24 ============================================================== ;========================================================================================= ghi_byte: ldi r17,8 ghi_24: rol r16 sbi AT24,data_24 brcs tiep_ghi_24 cbi AT24,data_24 tiep_ghi_24: rcall delay_1us sbi AT24,clock_24 rcall delay_1us cbi AT24,clock_24 dec r17 cpi r17,0 brne ghi_24 cbi AT24_D,data_24 sbi AT24,data_24 rcall delay_1us sbi AT24,clock_24 rcall delay_1us cbi AT24,clock_24 rcall delay_1us cbi AT24,data_24 sbi AT24_D,data_24 rcall delay_1us ret ;========================================================================================= ;CHUONG TRINH CON READ 24 ============================================================== ;========================================================================================= doc_byte: cbi AT24_D,data_24 sbi AT24,data_24 ldi r17,8 doc_24: sbi AT24,clock_24 rcall delay_1us sec sbis AT24_P,data_24 clc rol r16 cbi AT24,clock_24 rcall delay_1us dec r17 cpi r17,0 brne doc_24 cbi AT24,data_24 sbi AT24_D,data_24 rcall delay_1us ret ;========================================================================================= ;CHUONG TRINH CON ACK 24 ============================================================== ;========================================================================================= ACK: rcall delay_1us cbi AT24,data_24 rcall delay_1us sbi AT24,clock_24 rcall delay_1us cbi AT24,clock_24 rcall delay_1us ret ;========================================================================================= ;CHUONG TRINH CON NAK 24 ============================================================== ;========================================================================================= NAK: rcall delay_1us sbi AT24,data_24 rcall delay_1us sbi AT24,clock_24 rcall delay_1us cbi AT24,clock_24 rcall delay_1us ret ;========================================================================================= ;CHUONG TRINH CON RESET 24 ============================================================== ;========================================================================================= reset_ROM: ldi r17,9 sbi AT24,data_24 rcall delay_1us lap_reset_ROM: sbi AT24,clock_24 rcall delay_1us cbi AT24,clock_24 rcall delay_1us dec r17 cpi r17,0 brne lap_reset_ROM ret ;========================================================================================= ;CHUONG TRINH CON DELAY ================================================================== ;========================================================================================= delay_1us: ldi r23,9 lap_delay_1us: dec r23 cpi r23,0 brne lap_delay_1us ret ;----------------------------------- delay_5ms: ldi r16,0 ldi r17,0 lap_delay_5ms: inc r16 cpi r16,0 brne lap_delay_5ms inc r17 cpi r17,0 brne lap_delay_5ms ret ;========================================================================================= ;CHUONG TRINH CON SEND ADDRESS 24 ============================================================== ;========================================================================================= send_address: rcall reset_ROM rcall delay_5ms rcall delay_5ms rcall start ldi r16,0xa0 rcall ghi_byte mov r16,cursel_high rcall ghi_byte mov r16,cursel_low ;dia chi vung nho rcall ghi_byte ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** .org 0x0800 ;========================================================================================= ;CHUONG TRINH CON KIEU DICH LONG LED NGANG =============================================== ;========================================================================================= kieu_long_ngang_begin: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,high(chieu_dai_bang) ldi cursel_do_low,low(chieu_dai_bang) sub cursel_do_low,m_cursel_low sbc cursel_do_high,m_cursel_high mov cursel_a,cursel_do_low mov cursel_b,cursel_do_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_long_ngang_begin: cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs notx_kieu_long_ngang_begin ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh ;----------------------------- notx_kieu_long_ngang_begin: cpi cursel_do_low,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_do_high,r16 brsh notd_kieu_long_ngang_begin ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- notd_kieu_long_ngang_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_long_ngang_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_long_ngang_begin ret ;=============================================== kieu_long_ngang_end: ldi cursel_low,0 ldi cursel_high,0 mov cursel_xanh_high,m_cursel_high mov cursel_xanh_low,m_cursel_low ldi cursel_do_high,0 ldi cursel_do_low,0 mov cursel_a,m_cursel_low mov cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_long_ngang_end: cpi cursel_xanh_low,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_xanh_high,r16 brsh notx_kieu_long_ngang_end ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh ;----------------------------- notx_kieu_long_ngang_end: cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brcs notd_kieu_long_ngang_end ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- notd_kieu_long_ngang_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_long_ngang_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_long_ngang_end ;chieu_dai_bang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU CHAY CHU ========================================================= ;========================================================================================= kieu_chay_chu: ldi r16,low(chieu_dai_bang) ldi r17,high(chieu_dai_bang) cp m_cursel_low,r16 cpc m_cursel_high,r17 brlo kieu_trai_qua_begin ldi cursel_low,0 ldi cursel_high,0 mov cursel_xanh_high,m_cursel_high mov cursel_xanh_low,m_cursel_low subi cursel_xanh_low,low(chieu_dai_bang) sbci cursel_xanh_high,high(chieu_dai_bang) mov cursel_do_high,cursel_xanh_high mov cursel_do_low,cursel_xanh_low sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chay_chu: cp cursel_xanh_low,m_vi_tri_rot_low cpc cursel_xanh_high,m_vi_tri_rot_high brsh lon_hon_kieu_chay_chu mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- lon_hon_kieu_chay_chu: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_chay_chu ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_chay_chu ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH TRAI QUA ================================================== ;========================================================================================= kieu_trai_qua_begin: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_trai_qua_begin: cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_trai_qua_begin ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_trai_qua_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_trai_qua_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_trai_qua_begin ret ;================================================ kieu_trai_qua_end: ldi cursel_low,0 ldi cursel_high,0 mov cursel_xanh_high,m_cursel_high mov cursel_xanh_low,m_cursel_low mov cursel_do_high,m_cursel_high mov cursel_do_low,m_cursel_low sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_trai_qua_end: cpi cursel_xanh_low,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_xanh_high,r16 brsh not_kieu_trai_qua_end ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_trai_qua_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_trai_qua_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_trai_qua_end ;chieu_dai_bang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH PHAI QUA ================================================== ;========================================================================================= kieu_phai_qua_begin: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,high(chieu_dai_bang) ldi cursel_xanh_low,low(chieu_dai_bang) sub cursel_xanh_low,m_cursel_low sbc cursel_xanh_high,m_cursel_high mov cursel_do_low,cursel_xanh_low mov cursel_do_high,cursel_xanh_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_phai_qua_begin: cpi cursel_do_low,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_do_high,r16 brsh not_kieu_phai_qua_begin ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_phai_qua_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_phai_qua_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_phai_qua_begin ret ;================================================ kieu_phai_qua_end: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_phai_qua_end: cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brcs not_kieu_phai_qua_end ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_phai_qua_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_phai_qua_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_phai_qua_end ;chieu_dai_bang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU CHE TRAI QUA ================================================== ;========================================================================================= kieu_che_trai_qua_begin: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_trai_qua_begin: sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brsh not_kieu_che_trai_qua_begin ;neu lon hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_che_trai_qua_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_trai_qua_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_trai_qua_begin ret ;================================================ kieu_che_trai_qua_end: ldi cursel_low,0 ldi cursel_high,0 mov cursel_xanh_high,m_cursel_high mov cursel_xanh_low,m_cursel_low mov cursel_do_high,m_cursel_high mov cursel_do_low,m_cursel_low sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_trai_qua_end: cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brlo not_kieu_che_trai_qua_end ;neu nho hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_che_trai_qua_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_trai_qua_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_trai_qua_end ;chieu_dai_bang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU CHE PHAI QUA ================================================== ;========================================================================================= kieu_che_phai_qua_begin: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high mov cursel_xanh_high,cursel_b mov cursel_xanh_low,cursel_a mov cursel_do_high,cursel_b mov cursel_do_low,cursel_a sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_phai_qua_begin: cp cursel_low,cursel_a cpc cursel_high,cursel_b brlo not_kieu_che_phai_qua_begin ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_che_phai_qua_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_phai_qua_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_phai_qua_begin ret ;================================================ kieu_che_phai_qua_end: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_phai_qua_end: sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do cp cursel_low,cursel_a cpc cursel_high,cursel_b brsh not_kieu_che_phai_qua_end ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_che_phai_qua_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_phai_qua_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_phai_qua_end ;chieu_dai_bang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH ROT CHU PHAI QUA ========================================== ;========================================================================================= kieu_rot_phai_qua_begin: mov r16,m_vi_tri_hang cpi r16,0 brne tiep_kieu_rot_phai_qua_begin mov cursel_a,m_cursel_low mov cursel_b,m_cursel_high subi cursel_a,low(-1) sbci cursel_b,high(-1) mov m_cursel_low,cursel_a mov m_cursel_high,cursel_b subi cursel_a,low(-1) sbci cursel_b,high(-1) cpi cursel_a,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_b,r16 brlo tiep_kieu_rot_phai_qua_begin ;chieu_dai_bang rcall tim_diem_rot tiep_kieu_rot_phai_qua_begin: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do mov r16,m_vi_tri_rot_low cpi r16,0 brne lap_kieu_rot_phai_qua_begin_1 mov r16,m_vi_tri_rot_high cpi r16,0 brne lap_kieu_rot_phai_qua_begin_1 ldi YL,0 ldi YH,0 rcall tim_diem_rot lap_kieu_rot_phai_qua_begin_1: cp cursel_low,m_vi_tri_rot_low cpc cursel_high,m_vi_tri_rot_high brsh lon_hon_kieu_rot_phai_qua mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) rjmp lap_kieu_rot_phai_qua_begin_1 ;----------------------------- lon_hon_kieu_rot_phai_qua: ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high mov ZL,cursel_a mov ZH,cursel_b add cursel_a,m_vi_tri_rot_low adc cursel_b,m_vi_tri_rot_high add ZL,YL adc ZH,YH lap_kieu_rot_phai_qua_begin_2: sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_rot_phai_qua_begin ;neu nho hon khong xuat data mau (dang dich vao) cp cursel_low,ZL cpc cursel_high,ZH brsh not_kieu_rot_phai_qua_begin mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_rot_phai_qua_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_rot_phai_qua_begin_2 ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_rot_phai_qua_begin_2 ;chieu_dai_bang ret ;------------------------------------ tim_diem_rot: rcall text_co_ky_tu cpi cursel_a,low(chieu_dai_bang) brne tiep_tim_diem_rot cpi cursel_b,high(chieu_dai_bang) brne tiep_tim_diem_rot ret tiep_tim_diem_rot: mov m_vi_tri_rot_low,cursel_a mov m_vi_tri_rot_high,cursel_b mov m_cursel_low,cursel_a mov m_cursel_high,cursel_b rcall text_het_ky_tu mov YL,cursel_a mov YH,cursel_b ret ;------------------------------------ text_co_ky_tu: mov cursel_a,YL mov cursel_b,YH lap_text_co_ky_tu: subi cursel_a,low(-1) sbci cursel_b,high(-1) cpi cursel_a,low(chieu_dai_bang) brne tiep_text_co_ky_tu cpi cursel_b,high(chieu_dai_bang) brne tiep_text_co_ky_tu ret tiep_text_co_ky_tu: ldi XH,vung_xanh_low ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne thoat_text_co_ky_tu ldi XH,vung_xanh_high ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne thoat_text_co_ky_tu ldi XH,vung_do_low ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne thoat_text_co_ky_tu ldi XH,vung_do_high ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne thoat_text_co_ky_tu rjmp lap_text_co_ky_tu thoat_text_co_ky_tu: ret ;------------------------------------ text_het_ky_tu: mov cursel_a,m_vi_tri_rot_low mov cursel_b,m_vi_tri_rot_high lap_text_het_ky_tu: subi cursel_a,low(-1) sbci cursel_b,high(-1) cpi cursel_a,low(chieu_dai_bang) brne tiep_text_het_ky_tu cpi cursel_b,high(chieu_dai_bang) brne tiep_text_het_ky_tu ret tiep_text_het_ky_tu: ldi XH,vung_xanh_low ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne lap_text_het_ky_tu ldi XH,vung_xanh_high ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne lap_text_het_ky_tu ldi XH,vung_do_low ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne lap_text_het_ky_tu ldi XH,vung_do_high ldi XL,0 add XL,cursel_a ;diem dau vung can hien thi low adc XH,cursel_b ;diem dau vung can hien thi hight ld r16,X cpi r16,0xff brne lap_text_het_ky_tu ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DAN PHAI VAO ====================================================== ;========================================================================================= kieu_dan_phai_vao_begin: mov r16,m_vi_tri_rot_low cpi r16,0 brne kieu_dan_phai_vao_begin1 mov r16,m_vi_tri_hang cpi r16,0 brne tiep_kieu_dan_phai_vao_begin1 mov cursel_a,m_cursel_low mov cursel_b,m_cursel_high subi cursel_a,low(-1) sbci cursel_b,high(-1) cpi cursel_a,low(chieu_dai_bang) brne tiep_kieu_dan_phai_vao_begin1 cpi cursel_b,high(chieu_dai_bang) brne tiep_kieu_dan_phai_vao_begin1 ;chieu_dai_bang clr m_cursel_high clr m_cursel_low inc m_vi_tri_rot_low tiep_kieu_dan_phai_vao_begin1: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_dan_phai_vao_begin1: cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_dan_phai_vao_begin ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne not_kieu_dan_phai_vao_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne not_kieu_dan_phai_vao_begin ret ;----------------------------- not_kieu_dan_phai_vao_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_dan_phai_vao_begin1 ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_dan_phai_vao_begin1 ret ;============================== kieu_dan_phai_vao_begin1: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_dan_phai_vao_begin2: cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brsh lon_kieu_dan_phai_vao_begin ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) rjmp lap_kieu_dan_phai_vao_begin2 ;----------------------------- lon_kieu_dan_phai_vao_begin: mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne tiep_kieu_dan_phai_vao_begin2 cpi cursel_high,high(chieu_dai_bang) brne tiep_kieu_dan_phai_vao_begin2 ret tiep_kieu_dan_phai_vao_begin2: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lon_kieu_dan_phai_vao_begin cpi cursel_high,high(chieu_dai_bang) brne lon_kieu_dan_phai_vao_begin ret ;================================================== kieu_dan_phai_vao_end: ldi cursel_low,0 ldi cursel_high,0 mov cursel_xanh_high,m_cursel_high mov cursel_xanh_low,m_cursel_low mov r16,cursel_xanh_low mov r17,cursel_xanh_high ldi r18,2 rcall Div mov cursel_xanh_high,r17 mov cursel_xanh_low,r16 add cursel_xanh_low,r18 mov cursel_do_high,cursel_xanh_high mov cursel_do_low,cursel_xanh_low sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_dan_phai_vao_end: mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brsh lon_kieu_trai_qua_end sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lon_kieu_trai_qua_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lon_kieu_trai_qua_end ret lon_kieu_trai_qua_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_dan_phai_vao_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_dan_phai_vao_end ;chieu_dai_bang ret ;***************************************************************************************** ;***************************************************************************************** ;*****************************************************************************************
;========================================================================================= ;CHUONG TRINH CON KIEU CHIA DOI VAO ================================================== ;========================================================================================= kieu_chia_doi_vao_begin: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__cdvb rcall bat_led ret not_bang__cdvb: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_do_high,high(nua_chieu_dai_bang) ldi cursel_do_low,low(nua_chieu_dai_bang) sub cursel_do_low,m_cursel_low sbc cursel_do_high,m_cursel_high mov cursel_xanh_low,cursel_do_low mov cursel_xanh_high,cursel_do_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_tvao_begin: cpi cursel_do_low,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc cursel_do_high,r16 brsh not_kieu_chia_doi_tvao_begin ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led inc cursel_low rjmp lap_kieu_chia_doi_tvao_begin ;----------------------------- not_kieu_chia_doi_tvao_begin: ldi cursel_xanh_high,high(nua_chieu_dai_bang) ldi cursel_xanh_low,low(nua_chieu_dai_bang) ldi cursel_do_high,high(nua_chieu_dai_bang) ldi cursel_do_low,low(nua_chieu_dai_bang) ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_pvao_begin: cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_chia_doi_pvao_begin ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_chia_doi_pvao_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_chia_doi_pvao_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_chia_doi_pvao_begin ret ;================================================ kieu_chia_doi_vao_end: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__cdve rcall tat_led ret not_bang__cdve: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_tvao_end: cpi cursel_low,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc cursel_high,r16 brsh ben_phai_chia_doi_vao_end cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brcs not_kieu_chia_doi_tvao_end ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do not_kieu_chia_doi_tvao_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led inc cursel_low brne lap_kieu_chia_doi_tvao_end ;----------------------------- ben_phai_chia_doi_vao_end: ldi cursel_xanh_high,high(nua_chieu_dai_bang) ldi cursel_xanh_low,low(nua_chieu_dai_bang) add cursel_xanh_high,m_cursel_high adc cursel_xanh_low,m_cursel_low mov cursel_do_high,cursel_xanh_high mov cursel_do_low,cursel_xanh_low sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_pvao_end: cpi cursel_xanh_low,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_xanh_high,r16 brsh not_kieu_chia_doi_pvao_end ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do not_kieu_chia_doi_pvao_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_chia_doi_pvao_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_chia_doi_pvao_end ;chieu_dai_bang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU CHIA DOI RA ================================================== ;========================================================================================= kieu_chia_doi_ra_begin: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__cdrb rcall bat_led ret not_bang__cdrb: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_a,low(nua_chieu_dai_bang) ldi cursel_b,high(nua_chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_tra_begin: cpi cursel_low,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc cursel_high,r16 brsh ben_phai_chia_doi_ra_begin cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_chia_doi_tra_begin ;neu nho hon khong xuat data mau (dang dich ra) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do not_kieu_chia_doi_tra_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led inc cursel_low brne lap_kieu_chia_doi_tra_begin ;----------------------------- ben_phai_chia_doi_ra_begin: ldi cursel_xanh_high,high(chieu_dai_bang) ldi cursel_xanh_low,low(chieu_dai_bang) sub cursel_xanh_low,m_cursel_low sbc cursel_xanh_high,m_cursel_high mov cursel_do_high,cursel_xanh_high mov cursel_do_low,cursel_xanh_low sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_pra_begin: cpi cursel_xanh_low,low(chieu_dai_bang) ldi r16,high(chieu_dai_bang) cpc cursel_xanh_high,r16 brsh not_kieu_chia_doi_pra_begin ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do not_kieu_chia_doi_pra_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_chia_doi_pra_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_chia_doi_pra_begin ;chieu_dai_bang ret ;================================================ kieu_chia_doi_ra_end: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__cdre rcall tat_led ret not_bang__cdre: ldi cursel_low,0 ldi cursel_high,0 mov cursel_do_high,m_cursel_high mov cursel_do_low,m_cursel_low mov cursel_xanh_low,m_cursel_low mov cursel_xanh_high,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_tra_end: cpi cursel_do_low,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc cursel_do_high,r16 brsh not_kieu_chia_doi_tra_end ;neu lon hon khong xuat data mau (vuot vung data) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led inc cursel_low rjmp lap_kieu_chia_doi_tra_end ;----------------------------- not_kieu_chia_doi_tra_end: ldi cursel_xanh_high,high(nua_chieu_dai_bang) ldi cursel_xanh_low,low(nua_chieu_dai_bang) ldi cursel_do_high,high(nua_chieu_dai_bang) ldi cursel_do_low,low(nua_chieu_dai_bang) ldi cursel_a,low(nua_chieu_dai_bang) ldi cursel_b,high(nua_chieu_dai_bang) add cursel_a,m_cursel_low adc cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_chia_doi_pra_end: cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_chia_doi_pra_end ;neu nho hon khong xuat data mau (dang dich vao) mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do ;----------------------------- not_kieu_chia_doi_pra_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_chia_doi_pra_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_chia_doi_pra_end ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU CHE CHIA DOI VAO ================================================== ;========================================================================================= kieu_che_chia_doi_vao_begin: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__ccdvb rcall bat_led ret not_bang__ccdvb: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_chia_doi_vao_begin: mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brcs not_kieu_che_chia_doi_vao_begin ;neu nho hon khong xuat data mau (dang dich vao) cp cursel_low,cursel_a cpc cursel_high,cursel_b brsh not_kieu_che_chia_doi_vao_begin sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do ;----------------------------- not_kieu_che_chia_doi_vao_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_chia_doi_vao_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_chia_doi_vao_begin ret ;================================================ kieu_che_chia_doi_vao_end: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__ccdve rcall tat_led ret not_bang__ccdve: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_a,low(chieu_dai_bang) ldi cursel_b,high(chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_chia_doi_vao_end: mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do cp cursel_low,m_cursel_low cpc cursel_high,m_cursel_high brcs not_kieu_che_chia_doi_vao_end ;neu nho hon khong xuat data mau (dang dich vao) cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs dich_data_che_chia_doi_vao_end ;----------------------------- not_kieu_che_chia_doi_vao_end: sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do dich_data_che_chia_doi_vao_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_chia_doi_vao_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_chia_doi_vao_end ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU CHE CHIA DOI RA ================================================== ;========================================================================================= kieu_che_chia_doi_ra_begin: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__ccdrb rcall bat_led ret not_bang__ccdrb: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_a,low(nua_chieu_dai_bang) ldi cursel_b,high(nua_chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high ldi YL,low(nua_chieu_dai_bang) ldi YH,high(nua_chieu_dai_bang) add YL,m_cursel_low adc YH,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_chia_doi_ra_begin: mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_che_chia_doi_ra_begin ;neu nho hon khong xuat data mau (dang dich ra) cp cursel_low,YL cpc cursel_high,YH brcs dich_data_che_chia_doi_ra_begin ;----------------------------- not_kieu_che_chia_doi_ra_begin: sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do dich_data_che_chia_doi_ra_begin: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_chia_doi_ra_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_chia_doi_ra_begin ret ;================================================ kieu_che_chia_doi_ra_end: mov r16,m_cursel_low cpi r16,low(nua_chieu_dai_bang) ldi r16,high(nua_chieu_dai_bang) cpc m_cursel_high,r16 brlo not_bang__ccdre rcall tat_led ret not_bang__ccdre: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_a,low(nua_chieu_dai_bang) ldi cursel_b,high(nua_chieu_dai_bang) sub cursel_a,m_cursel_low sbc cursel_b,m_cursel_high ldi YL,low(nua_chieu_dai_bang) ldi YH,high(nua_chieu_dai_bang) add YL,m_cursel_low adc YH,m_cursel_high sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_che_chia_doi_ra_end: mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do cp cursel_low,cursel_a cpc cursel_high,cursel_b brcs not_kieu_che_chia_doi_ra_end ;neu nho hon khong xuat data mau (dang dich ra) cp cursel_low,YL cpc cursel_high,YH brsh not_kieu_che_chia_doi_ra_end sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do ;----------------------------- not_kieu_che_chia_doi_ra_end: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_che_chia_doi_ra_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_che_chia_doi_ra_end ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH LONG DOC ===================================================== ;========================================================================================= kieu_long_doc_begin: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_kldb rcall bat_led ret not_bang_chieu_cao_bang_kldb: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 ldi cursel_a,16 sub cursel_a,m_cursel_low add cursel_a,m_vi_tri_hang mov cursel_b,m_vi_tri_hang add cursel_b,m_cursel_low subi cursel_b,16 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_long_doc_begin: cp m_cursel_low,m_vi_tri_hang brlo not_long_doc_begin_xanh mov vi_tri_hang,cursel_a rcall lay_bit_mau_xanh not_long_doc_begin_xanh: ldi r16,16 sub r16,m_cursel_low cp r16,m_vi_tri_hang brsh not_long_doc_begin_do mov vi_tri_hang,cursel_b rcall lay_bit_mau_do not_long_doc_begin_do: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_long_doc_begin ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_long_doc_begin ret ;----------------------------------------- kieu_long_doc_end: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_klde rcall tat_led ret not_bang_chieu_cao_bang_klde: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 mov cursel_a,m_vi_tri_hang sub cursel_a,m_cursel_low mov cursel_b,m_vi_tri_hang add cursel_b,m_cursel_low sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_kieu_long_doc_end: cp m_cursel_low,m_vi_tri_hang brsh not_long_doc_end_xanh mov vi_tri_hang,cursel_a rcall lay_bit_mau_xanh not_long_doc_end_xanh: ldi r16,16 sub r16,m_cursel_low cp r16,m_vi_tri_hang brlo not_long_doc_end_do mov vi_tri_hang,cursel_b rcall lay_bit_mau_do not_long_doc_end_do: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_kieu_long_doc_end ;chieu_dai_bang cpi cursel_high,high(chieu_dai_bang) brne lap_kieu_long_doc_end ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH LED TREN XUONG =============================================== ;========================================================================================= kieu_tren_xuong_begin: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_ktxb rcall bat_led ret nho_ktxb: rcall tat_led ret not_bang_chieu_cao_bang_ktxb: cp m_cursel_low,m_vi_tri_hang brlo nho_ktxb ldi vi_tri_hang,16 sub vi_tri_hang,m_cursel_low add vi_tri_hang,m_vi_tri_hang push m_vi_tri_hang mov m_vi_tri_hang,vi_tri_hang rcall bat_led pop m_vi_tri_hang ret ;----------------------------------------- kieu_tren_xuong_end: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_ktxe rcall tat_led ret lon_ktxe: rcall tat_led ret not_bang_chieu_cao_bang_ktxe: cp m_cursel_low,m_vi_tri_hang brsh lon_ktxe mov vi_tri_hang,m_vi_tri_hang sub vi_tri_hang,m_cursel_low push m_vi_tri_hang mov m_vi_tri_hang,vi_tri_hang rcall bat_led pop m_vi_tri_hang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH LED DUOI LEN ================================================= ;========================================================================================= kieu_duoi_len_begin: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_kdlb rcall bat_led ret lon_kdlb: rcall tat_led ret not_bang_chieu_cao_bang_kdlb: ldi r16,16 sub r16,m_cursel_low cp r16,m_vi_tri_hang brsh lon_kdlb mov vi_tri_hang,m_vi_tri_hang sub vi_tri_hang,r16 push m_vi_tri_hang mov m_vi_tri_hang,vi_tri_hang rcall bat_led pop m_vi_tri_hang ret ;----------------------------------------- kieu_duoi_len_end: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_kdle rcall tat_led ret nho_kdle: rcall tat_led ret not_bang_chieu_cao_bang_kdle: ldi r16,16 sub r16,m_cursel_low cp r16,m_vi_tri_hang brlo nho_kdle mov vi_tri_hang,m_vi_tri_hang add vi_tri_hang,m_cursel_low push m_vi_tri_hang mov m_vi_tri_hang,vi_tri_hang rcall bat_led pop m_vi_tri_hang ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH CHE LED TREN XUONFG ========================================== ;========================================================================================= kieu_che_tren_xuong_begin: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brsh lon_bang_chieu_cao_bang_kctxb cp m_cursel_low,m_vi_tri_hang brlo nho_kctxb lon_bang_chieu_cao_bang_kctxb: rcall bat_led ret nho_kctxb: rcall tat_led ret ;----------------------------------------- kieu_che_tren_xuong_end: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brsh lon_bang_chieu_cao_bang_kctxe cp m_cursel_low,m_vi_tri_hang brsh lon_bang_chieu_cao_bang_kctxe rcall bat_led ret lon_bang_chieu_cao_bang_kctxe: rcall tat_led ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU DICH CHE LED DUOI LEN =========================================== ;========================================================================================= kieu_che_duoi_len_begin: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brsh lon_chieu_cao_bang_kcdlb ldi cursel_a,16 sub cursel_a,m_cursel_low cp cursel_a,m_vi_tri_hang brsh lon_kcdlb lon_chieu_cao_bang_kcdlb: rcall bat_led ret lon_kcdlb: rcall tat_led ret ;----------------------------------------- kieu_che_duoi_len_end: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brsh lon_bang_chieu_cao_bang_kcdle ldi cursel_a,16 sub cursel_a,m_cursel_low cp cursel_a,m_vi_tri_hang brlo lon_bang_chieu_cao_bang_kcdle rcall bat_led ret lon_bang_chieu_cao_bang_kcdle: rcall tat_led ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU ROT XUONG ========================================================= ;========================================================================================= kieu_rot_xuong_begin: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_krxb mov r16,m_vi_tri_rot_low cpi r16,low(chieu_cao_bang) brne not_bang_chieu_cao_bang_krxb1 lon_hon_vi_tri_rot_xuong: rcall bat_led ret not_bang_chieu_cao_bang_krxb1: inc m_vi_tri_rot_low mov m_cursel_low,m_vi_tri_rot_low not_bang_chieu_cao_bang_krxb: ldi cursel_a,low(chieu_cao_bang) sub cursel_a,m_vi_tri_rot_low cp cursel_a,m_vi_tri_hang brlo lon_hon_vi_tri_rot_xuong mov cursel_b,m_cursel_low sub cursel_b,m_vi_tri_rot_low cp cursel_b,m_vi_tri_hang brne khac_krxb push m_vi_tri_hang mov m_vi_tri_hang,cursel_a rcall bat_led pop m_vi_tri_hang ret khac_krxb: rcall tat_led ret ;----------------------------------------- kieu_rot_xuong_end: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_krxe mov r16,m_vi_tri_rot_low cpi r16,low(chieu_cao_bang) brne not_bang_chieu_cao_bang_krxe1 khac_krxe: rcall tat_led ret not_bang_chieu_cao_bang_krxe1: inc m_vi_tri_rot_low ldi r16,low(chieu_cao_bang) mov m_cursel_low,r16 sub m_cursel_low,m_vi_tri_rot_low not_bang_chieu_cao_bang_krxe: ldi cursel_a,low(chieu_cao_bang) sub cursel_a,m_vi_tri_rot_low cp m_vi_tri_hang,cursel_a brlo nho_hon_vi_tri_rot_xuong cp m_cursel_low,m_vi_tri_hang brne khac_krxe push m_vi_tri_hang mov m_vi_tri_hang,cursel_a rcall bat_led pop m_vi_tri_hang ret nho_hon_vi_tri_rot_xuong: rcall bat_led ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU ROT XUONG ========================================================= ;========================================================================================= kieu_rot_len_begin: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_krlb mov r16,m_vi_tri_rot_low cpi r16,low(chieu_cao_bang) brne not_bang_chieu_cao_bang_krlb1 lon_hon_vi_tri_rot_len: rcall bat_led ret not_bang_chieu_cao_bang_krlb1: inc m_vi_tri_rot_low mov m_cursel_low,m_vi_tri_rot_low not_bang_chieu_cao_bang_krlb: cp m_vi_tri_hang,m_vi_tri_rot_low brlo lon_hon_vi_tri_rot_len ldi cursel_a,low(chieu_cao_bang) add cursel_a,m_vi_tri_rot_low sub cursel_a,m_cursel_low cp cursel_a,m_vi_tri_hang brne khac_krlb push m_vi_tri_hang mov m_vi_tri_hang,m_vi_tri_rot_low rcall bat_led pop m_vi_tri_hang ret khac_krlb: rcall tat_led ret ;----------------------------------------- kieu_rot_len_end: mov r16,m_cursel_low cpi r16,low(chieu_cao_bang) ldi r16,high(chieu_cao_bang) cpc m_cursel_high,r16 brlo not_bang_chieu_cao_bang_krle mov r16,m_vi_tri_rot_low cpi r16,low(chieu_cao_bang) brne not_bang_chieu_cao_bang_krle1 khac_krle: rcall tat_led ret not_bang_chieu_cao_bang_krle1: inc m_vi_tri_rot_low ldi r16,low(chieu_cao_bang) mov m_cursel_low,r16 sub m_cursel_low,m_vi_tri_rot_low not_bang_chieu_cao_bang_krle: cp m_vi_tri_rot_low,m_vi_tri_hang brlo nho_hon_vi_tri_rot_len ldi cursel_a,low(chieu_cao_bang) sub cursel_a,m_cursel_low cp cursel_a,m_vi_tri_hang brne khac_krle push m_vi_tri_hang mov m_vi_tri_hang,m_vi_tri_rot_low rcall bat_led pop m_vi_tri_hang ret nho_hon_vi_tri_rot_len: rcall bat_led ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON KIEU CHOP TAT LED======================================================= ;========================================================================================= kieu_chop_tat: sbrc m_cursel_low,4 ;cot dang tang rjmp tat_led bat_led: ldi cursel_low,0 ldi cursel_high,0 ldi cursel_xanh_high,0 ldi cursel_xanh_low,0 ldi cursel_do_high,0 ldi cursel_do_low,0 lap_bat_led: mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_xanh mov vi_tri_hang,m_vi_tri_hang rcall lay_bit_mau_do sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_bat_led cpi cursel_high,high(chieu_dai_bang) brne lap_bat_led ret ;========================== tat_led: ldi cursel_low,0 ldi cursel_high,0 sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh sbi chan_dk,chan_do ;mac dinh la tat mau do lap_tat_led: sbi chan_dk,ck_led ;kich ck cbi chan_dk,ck_led subi cursel_low,low(-1) sbci cursel_high,high(-1) cpi cursel_low,low(chieu_dai_bang) brne lap_tat_led cpi cursel_high,high(chieu_dai_bang) brne lap_tat_led ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LAY BIT MAU XANH ================================================== ;========================================================================================= lay_bit_mau_xanh: ldi XH,vung_xanh_low ldi XL,0 cpi vi_tri_hang,8 ;r18 vi tri hang brlo bang_thap_xanh subi vi_tri_hang,8 ldi XH,vung_xanh_high bang_thap_xanh: add XL,cursel_xanh_low ;diem dau vung can hien thi low adc XH,cursel_xanh_high ;diem dau vung can hien thi hight ld r16,X subi cursel_xanh_low,low(-1) sbci cursel_xanh_high,high(-1) sbi chan_dk,chan_xanh ;mac dinh la tat mau xanh cpi vi_tri_hang,4 brsh hang_xanh_lon_hon_bang_4 cpi vi_tri_hang,0 brne not_hang_xanh_0 sbrs vi_tri_hang,0 ;neu bit 0 = 1 thi nhay lenh ret sbrs r16,0 cbi chan_dk,chan_xanh ret ;------------------------- not_hang_xanh_0: cpi vi_tri_hang,1 brne not_xanh_hang_1 sbrs r16,1 cbi chan_dk,chan_xanh ret ;------------------------- not_xanh_hang_1: cpi vi_tri_hang,2 brne not_xanh_hang_2 sbrs r16,2 cbi chan_dk,chan_xanh ret ;------------------------- not_xanh_hang_2: sbrs r16,3 cbi chan_dk,chan_xanh ret ;------------------------- hang_xanh_lon_hon_bang_4: cpi vi_tri_hang,4 brne not_xanh_hang_4 sbrs r16,4 cbi chan_dk,chan_xanh ret ;------------------------- not_xanh_hang_4: cpi vi_tri_hang,5 brne not_xanh_hang_5 sbrs r16,5 cbi chan_dk,chan_xanh ret ;------------------------- not_xanh_hang_5: cpi vi_tri_hang,6 brne not_xanh_hang_6 sbrs r16,6 cbi chan_dk,chan_xanh ret ;------------------------- not_xanh_hang_6: sbrs r16,7 cbi chan_dk,chan_xanh ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** ;========================================================================================= ;CHUONG TRINH CON LAY BIT MAU XANH ================================================== ;========================================================================================= lay_bit_mau_do: ldi XH,vung_do_low ldi XL,0 cpi vi_tri_hang,8 ;r18 vi tri hang brlo bang_thap_do subi vi_tri_hang,8 ldi XH,vung_do_high bang_thap_do: add XL,cursel_do_low ;diem dau vung can hien thi low adc XH,cursel_do_high ;diem dau vung can hien thi hight ld r16,X subi cursel_do_low,low(-1) sbci cursel_do_high,high(-1) sbi chan_dk,chan_do ;mac dinh la tat mau do cpi vi_tri_hang,4 brsh hang_do_lon_hon_bang_4 cpi vi_tri_hang,0 brne not_do_hang_0 sbrs r16,0 ;neu bit 0 = 1 thi nhay lenh ret cbi chan_dk,chan_do ret ;------------------------- not_do_hang_0: cpi vi_tri_hang,1 brne not_do_hang_1 sbrs r16,1 cbi chan_dk,chan_do ret ;------------------------- not_do_hang_1: cpi vi_tri_hang,2 brne not_do_hang_2 sbrs r16,2 cbi chan_dk,chan_do ret ;------------------------- not_do_hang_2: sbrs r16,3 cbi chan_dk,chan_do ret ;------------------------- hang_do_lon_hon_bang_4: cpi vi_tri_hang,4 brne not_do_hang_4 sbrs r16,4 cbi chan_dk,chan_do ret ;------------------------- not_do_hang_4: cpi vi_tri_hang,5 brne not_do_hang_5 sbrs r16,5 cbi chan_dk,chan_do ret ;------------------------- not_do_hang_5: cpi vi_tri_hang,6 brne not_do_hang_6 sbrs r16,6 cbi chan_dk,chan_do ret ;------------------------- not_do_hang_6: sbrs r16,7 cbi chan_dk,chan_do ret ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** Chu_nhat: .db "Ch", u3, " nh", a65, "t " Thu: .db "Th", u71, ' ' hai: .db "hai " ba: .db "ba " tu: .db 't', u7, " " nam: .db 'n', a8, "m " sau: .db 's', a1, "u " bay: .db 'b', a3, "y " ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** receiving_data: .db 0x00,0x54 ;R .db 0x0f,0xc0 .db 0x0f,0xc0 .db 0xef,0xf9 .db 0xef,0xf5 .db 0x0f,0xcc .db 0x1f,0xde .db 0xff,0xff ;e .db 0xff,0xe0 .db 0x7f,0xc0 .db 0x7f,0xdb .db 0x7f,0xdb .db 0x7f,0xc8 .db 0xff,0xe8 .db 0xff,0xff ;c .db 0xff,0xe0 .db 0x7f,0xc0 .db 0x7f,0xdf .db 0x7f,0xdf .db 0x7f,0xce .db 0xff,0xee .db 0xff,0xff ;e .db 0xff,0xe0 .db 0x7f,0xc0 .db 0x7f,0xdb .db 0x7f,0xdb .db 0x7f,0xc8 .db 0xff,0xe8 .db 0xff,0xff ;i .db 0x5f,0xc0 .db 0x5f,0xc0 .db 0xff,0xff ;v .db 0x7f,0xff .db 0x7f,0xf8 .db 0xff,0xe1 .db 0xff,0xcf .db 0xff,0xe1 .db 0x7f,0xf8 .db 0x7f,0xff .db 0xff,0xff ;i .db 0x5f,0xc0 .db 0x5f,0xc0 .db 0xff,0xff ;n .db 0x7f,0xc0 .db 0x7f,0xc0 .db 0x7f,0xff .db 0x7f,0xc0 .db 0xff,0xc0 .db 0xff,0xff ;g .db 0xff,0xb0 .db 0x7f,0x20 .db 0x7f,0x6f .db 0x7f,0x6f .db 0x7f,0x0 .db 0x7f,0x80 .db 0xff,0xff ; ; .db 0xff,0xff .db 0xff,0xff .db 0xff,0xff .db 0xff,0xff ;d .db 0xff,0xe0 .db 0x7f,0xc0 .db 0x7f,0xdf .db 0x0f,0xc0 .db 0x0f,0xc0 .db 0xff,0xff ;a .db 0xff,0xe6 .db 0x7f,0xc2 .db 0x7f,0xdb .db 0x7f,0xe9 .db 0x7f,0xc0 .db 0xff,0xc0 .db 0xff,0xff ;t .db 0x7f,0xff .db 0x1f,0xe0 .db 0x0f,0xc0 .db 0x7f,0xcf .db 0xff,0xef .db 0xff,0xff ;a .db 0xff,0xe6 .db 0x7f,0xc2 .db 0x7f,0xdb .db 0x7f,0xe9 .db 0x7f,0xc0 .db 0xff,0xc0 .db 0xff,0xff ;***************************************************************************************** ;***************************************************************************************** ;***************************************************************************************** No_data: .db 0x00,0x2b ;N .db 0x0f,0xc0 .db 0x0f,0xc0 .db 0x3f,0xfe .db 0xff,0xe1 .db 0x0f,0xc0 .db 0x0f,0xc0 .db 0xff,0xff ;o .db 0xff,0xe0 .db 0x7f,0xc0 .db 0x7f,0xdf .db 0x7f,0xdf .db 0x7f,0xc0 .db 0xff,0xe0 .db 0xff,0xff ; ; .db 0xff,0xff .db 0xff,0xff .db 0xff,0xff .db 0xff,0xff ;d .db 0xff,0xe0 .db 0x7f,0xc0 .db 0x7f,0xdf .db 0x0f,0xc0 .db 0x0f,0xc0 .db 0xff,0xff ;a .db 0xff,0xe6 .db 0x7f,0xc2 .db 0x7f,0xdb .db 0x7f,0xe9 .db 0x7f,0xc0 .db 0xff,0xc0 .db 0xff,0xff ;t .db 0x7f,0xff .db 0x1f,0xe0 .db 0x0f,0xc0 .db 0x7f,0xcf .db 0xff,0xef .db 0xff,0xff ;a .db 0xff,0xe6 .db 0x7f,0xc2 .db 0x7f,0xdb .db 0x7f,0xe9 .db 0x7f,0xc0 .db 0xff,0xc0 .db 0xff,0xff
Comment