Counter 51
Blogroll: Cheap archery bow | Low price lcdtv | Best buy dance pants
Project Microprocessor Report




Ninja!
Memories Of microprocessor
microprocessor
Project
18 ตุลาคม 2550

                     Project

        โปรแกรมบวกเลข BCD หนึ่งหลักสองจำนวน โดยขณะเริ่มทำงาน โปรแกรมจะทำการรอการเกิด interrupt ที่ external interrupt 0 โดยขณะที่ไม่มีการเกิดการ interrupt ที่ external interrupt 0 นั้น led ที่ p1.7 จะ blink ด้วยความถี่ 1 hz ด้วย duty cycle < 50% เมื่อมีการ interrupt led ที่ p1.7 จะหยุด blink แล้วเข้าสู่โปรแกรมบวกเลข โดยจะรอรับการกดเลข BCD ตัวตั้ง และ ตัวบวก โดยผลลัพท์จากการบวกรวมทั้งตัวทดจะแสดงที่ monitor ส่วน ที่ 7-segment display จะแสดงเฉพาะผลบวกของ BCD ทั้ง 2 จำนวนเท่านั้น ในกรณีที่มีตัวทดออก (carry out) led ที่ p1.7 จะสว่างค้าง โดยเมื่อทำการบวกข้างต้นเสร็จสิ้นแล้ว โปรแกรมจะทำการหยุดรอการกด key ใดๆ บน keyboard เมื่อมีการกดปุ่มใดๆ บน keyboard โปรแกรมจะทำการกลับไปรอการเกิด external interrupt 0 อีกครั้ง และ led ที่ p1.7 จะกลับไป blink อีกครั้ง แล้วทำ loop  ลักษณะเช่นนี้ไปเรื่อยๆ


$mod51
$include(mypaulm2.equ)


      dseg at 20h


flag1: ds 1


      dseg at 50h


tick: ds 1
tock: ds 1
num1: ds 1
num2: ds 1
rent: ds 1
equal: ds 1


      cseg at 8000h


      jmp start


      org 8003h
      jmp external_interrupt0


      org 8100h


start:
      mov dptr,#ready?
      call pstr
      call newline
      call newline


      mov tick,#0
      mov tock,#0


      orl tmod,#1


      setb tr0
      setb ea
      setb ex0


main:
      call timer_for_blink
      call led_on
      call led_off
      jmp main


external_interrupt0:


      push acc
      push psw


      clr ac
      setb p1.7


      mov dptr,#first
      call pstr


      call cin
      mov num1,a
      call cout
      mov a,num1
      call asc2hex
      mov num1,a


      call newline
      call newline


      mov dptr,#second
      call pstr


      call cin
      mov num2,a
      call cout
      mov a,num2
      call asc2hex
      mov num2,a


      call newline
      call newline


      mov dptr,#result
      call pstr


      clr ac
      mov a,num1
      add a,53h
      da a
      mov equal,a


      call phex


      call seven_segment_display0


      call newline
      call newline


      call cin


      mov dptr,#ready?
      call pstr


      call newline
      call newline


      pop psw
      pop acc


      reti


timer_for_blink:


      jnb tf0,$
      clr tf0


      orl th0,#0dch
      inc tock
      mov a,tock
      cjne a,#100,exit_blink
      mov tock,#0


      setb flag1.0


exit_blink:


      ret


led_on:


      jnb flag1.0,exit_led_on
      clr flag1.0
      setb flag1.1
      clr p1.7


exit_led_on:


      ret


led_off:


      jnb flag1.1,exit_led_off
      inc tick
      mov a,tick
      cjne a,#5,exit_led_off
      mov tick,#0
      clr flag1.1
      setb p1.7


exit_led_off:


      ret


seven_segment_display0:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#0h,seven_segment_display1


      mov p1,#0c0h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      ov a,#0
      mov a,54h
      cjne a,#1,zero
      clr p1.7


zero: ret


seven_segment_display1:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#01h,seven_segment_display2


      mov p1,#0f9h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,one
      clr p1.7


one: ret


seven_segment_display2:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#02h,seven_segment_display3


      mov p1,#0a4h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,two
      clr p1.7


two: ret


seven_segment_display3:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#03h,seven_segment_display4


      mov p1,#0b0h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,three
      clr p1.7


three: ret


seven_segment_display4:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#04h,seven_segment_display5


      mov p1,#099h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,four
      clr p1.7


four:  ret


seven_segment_display5:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#05h,seven_segment_display6


      mov p1,#092h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,five
      clr p1.7


five: ret


seven_segment_display6:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#06h,seven_segment_display7


      mov p1,#082h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,six
      clr p1.7


six: ret


seven_segment_display7:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#07h,seven_segment_display8


      mov p1,#0f8h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,seven
      clr p1.7


seven: ret


seven_segment_display8:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#08h,seven_segment_display9


      mov p1,#080h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,eight
      clr p1.7


eight: ret


seven_segment_display9:


    ; mov a,equal


      mov a,#0
      mov r1,#54h
      mov 54h,55h
      xchd a,@r1


      cjne a,#09h,exit_seven_segment


      mov p1,#090h


      mov rent,#0
      mov r1,#54h
      mov a,equal
      rr a
      rr a
      rr a
      rr a
      xchd a,@r1
      mov a,#0
      mov a,54h
      cjne a,#1,eight
      clr p1.7


nine: ret


exit_seven_segment:


      ret


on_carry:


      setb flag1.2


 


first: db 'Enter First Number to add:>',0


second: db 'Enter Second Number to add:>',0


ready?: db '***Wait for External_Interrupt,led blink***',0


result: db 'BCD number is (led on if carry out:>',0



 end


 



posted @ 16:33:05 น. | Not Allow Comments




YourName: (* Require)
www:
* กดครั้งเดียวพอนะครับ


Privacy policy | Terms | Disclaimer | Contact
Copyright © Story owner & StoryThai.com. All rights reserved.