??? 07/01/05 08:41 Read: times |
#96375 - count down with 8051 Responding to: ???'s previous message |
Dear Alex
this code is very clumsy but it work for my 5 digits count up and down project ;chöông trình coil.asm ñeå vaän haønh moät maùy quaán daây, nhaäp soá voøng daây caàn quaán ;sau ñoù maùy seõ ngöøng khi soá voøng ñaõ ñuû ; $mod52 ;taäp hôïp caùc maõ display töø 0 ñeán 9 zero equ 00000010b ;maõ mask cuûa caùc soá töø 0 ñeán 9 mot equ 01011110b ; hai equ 00101000b ba equ 01001000b bon equ 01010100b nam equ 01000001b sau equ 00000001b bay equ 01011010b tam equ 00000000b chin equ 01000000b ;taäp hôïp caùc chaân led drive don_vi bit p3.5 chuc bit p3.4 tram bit p3.1 ngan bit p3.0 chuc_ngan bit p3.7 ;thoâng tin veà trò soá ñeám chöùa vaøo caùc register ni unit equ 35h ten equ 36h hundred equ 37h thousand equ 38h ten_thousand equ 39h count1 equ 40h count2 equ 41h count3 equ 42h count4 equ 43h count5 equ 44h led_out equ p1 ;=============================================================== org 00h ;vectô reset ljmp start ;nhaåy tôùi start org 03h ;external0 interrupt ljmp count_up ; nhaåy tôùi isr cuûa count_up org 0bh ;timer 0 interrupt ljmp update org 13h ;external1 interrupt ljmp count_down org 50h ;locate beginning of rest of program ;================================================================= init_baud: mov psw,#00h mov tmod, #00100001b ;ñaët timer0 chaïy 8 bit auto reload setb ea setb et0 setb tr0 setb it0 setb it1 setb ex0 setb ex1 ret update: mov th0, #-50 ; ñaët trò cho caùc timer reg mov tl0, #-50 ; ñeå taïo khoaûng ñeám 1/100 giaây mov unit,count1 lcall display_don_vi mov ten,count2 lcall display_chuc mov hundred,count3 lcall display_tram mov thousand,count4 lcall display_ngan mov ten_thousand,count5 lcall display_10ngan reti ; count_up: push acc push psw clr ex1 mov a,count1 add a,#01h da a mov count1,a cjne a,#10h,xong_isr mov count1,#00h mov a,count2 add a,#01h da a mov count2,a cjne a,#10h,xong_isr mov count2,#00h mov a,count3 add a,#01h da a mov count3,a cjne a,#10h,xong_isr mov count3,#00h mov a,count4 add a,#01h da a mov count4,a cjne a,#10h,xong_isr mov count4,#00h mov a,count5 add a,#01h da a mov count5,a cjne a,#10h,xong_isr mov count5,#00h xong_isr: setb ex1 pop psw pop acc ; traû laïi cho a reti count_down: push acc push psw clr ex0 mov a,count1 dec a mov count1,a cjne a,#-1,exit_count mov count1,#9 mov a,count2 dec a mov count2,a cjne a,#-1,exit_count mov count2,#9 mov a,count3 dec a mov count3,a cjne a,#-1,exit_count mov count3,#9 mov a,count4 dec a mov count4,a cjne a,#-1,exit_count mov count4,#9 mov a,count5 dec a mov count5,a cjne a,#-1,exit_count mov count5,#9 exit_count: setb ex0 pop psw pop acc reti delayms: ;loop delay 1/1000 sec mov r4,#00h loopa: inc r4 mov a,r4 cjne a,#0ffh,loopa ret ;************************************************************************** ; caùc c/t con tí töø display_0 tôùi display_9 thöïc ra laø caùc mask cuûa ñeøn led 7 ñoaïn ;vôùi key_port.7 veà phiaù traùi vaø key_port.0 beân phaûi,key_port.7 luoân off vì chæ duøng 7 bit thoâi. ;************************************************************************** display_0: mov led_out, #zero ret display_1: mov led_out, #mot ret display_2: mov led_out, #hai ret display_3: mov led_out, #ba ret display_4: mov led_out, #bon ret display_5: mov led_out, #nam ret display_6: mov led_out, #sau ret display_7: mov led_out, #bay ret display_8: mov led_out, #tam ret display_9: mov led_out, #chin ret ; caùi get number ni kieám soá caàn display vaø maàn luoân ; ñoïc data töø msb cuûa acc ñeå bieát soá naøo caàn display get_number: cjne a, #00h, so1 ; jump if not 0 acall display_0 ret so1: cjne a, #01h, so2 ; jump if not 1 acall display_1 ret so2: cjne a, #02h, so3 ; jump if not 2 acall display_2 ret so3: cjne a, #03h, so4 ; jump if not 3 acall display_3 ret so4: cjne a, #04h, so5 ; jump if not 4 acall display_4 ret so5: cjne a, #05h, so6 ; jump if not 5 acall display_5 ret so6: cjne a, #06h,so7 ; jump if not 6 acall display_6 ret so7: cjne a, #07h, so8 ; jump if not 7 acall display_7 ret so8: cjne a, #08h, so9 ; jump if not 8 acall display_8 ret so9: acall display_9 ; laø 9 chöù ñaâu nöõa ret ;********* display thousand digit ********************************* display_10ngan: mov led_out,#0ffh mov a, ten_thousand ; move hundreds into a (for get_number routine) anl a, #00fh acall get_number clr chuc_ngan ; turn on 5th digit lcall delayms setb chuc_ngan ret ;********* display thousand digit ********************************* display_ngan: mov led_out,#0ffh mov a, thousand ; move hundreds into a (for get_number routine) anl a, #00fh acall get_number clr ngan ; turn on 4th digit lcall delayms setb ngan ret ;********* display hundred digit ****************************** display_tram: mov led_out,#0ffh mov a, hundred ; move hundreds into a (for get_number routine) anl a, #00fh acall get_number clr tram ; turn on 3rd digit lcall delayms setb tram ret ;******** display ten digit *********************************** display_chuc: mov led_out,#0ffh mov a,ten anl a, #00fh acall get_number clr chuc lcall delayms setb chuc ret ;*********display unit digit **************************** display_don_vi: mov led_out,#0ffh mov a,unit anl a, #00fh acall get_number clr don_vi lcall delayms setb don_vi ret ;======================================================== start: lcall init_baud mov r0,#00h mov count1,#0 mov count2,#0 mov count3,#0 mov count4,#0 mov count5,#0 ret end have a good day Vu Nhu Khanh |
Topic | Author | Date |
Countdown with 8051 | 01/01/70 00:00 | |
No Code ,,, But an Idea | 01/01/70 00:00 | |
Tutorials | 01/01/70 00:00 | |
Hi. | 01/01/70 00:00 | |
Third way | 01/01/70 00:00 | |
I have a part of code... | 01/01/70 00:00 | |
Delays..... | 01/01/70 00:00 | |
Countdown | 01/01/70 00:00 | |
Show us the code ! | 01/01/70 00:00 | |
"The" code... | 01/01/70 00:00 | |
What ? | 01/01/70 00:00 | |
R1 and R2 | 01/01/70 00:00 | |
binary-decimal | 01/01/70 00:00 | |
Another trick | 01/01/70 00:00 | |
It's working... | 01/01/70 00:00 | |
Start your count decimal | 01/01/70 00:00 | |
count down with 8051![]() | 01/01/70 00:00 |