全新论坛MCU智学网上线,欢迎访问新论坛!稀缺资源、技术干货、参考设计、原厂资料尽在MCU智学网
更新自动建库工具PCB Footprint Expert 2023.13 Pro / Library Expert 破解版

用AT90S8515做的打铃程序

[复制链接]
2543 0

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有帐号?注册会员

x

  1. ;**** AVR编程说明 ********************************************************************
  2. ;* 编号:LRDZAVR0100 
  3. ;* 标题: 32点打铃器例程
  4. ;* 文件名:timecontr.asm
  5. ;* 版本: 1.0
  6. ;* 开始日期: 02.06.13
  7. ;* 目标MCU: AT90S8515
  8. ;* 技术支持:admin@mcuzx.com  
  9. ;* 硬件结构: PA0-5对应6个LED数显管的位 ,PC0-7对应各LED数显管的段 ,PB4-7为键盘。
  10. ;* 软件描述: 上电后,时钟从00.00.00(时/分/秒)自动走时,在走时状态时 , 按PB4(设定
  11. ;* 键)超过3秒可循环选择调整时间/工作参数 ,接着按PB5以确定选择的操作 ,进入调整操作后 ,
  12. ;* 按PB5选择欲调整参数,按PB6(增加键)完成调整参数操作 。按PB7,进入时控运行,PB1亮,
  13. ;* 再按PB7停止时控运行,回显走时。在定时到时,PB0点亮。
  14. ;*************************************************************************************
  15. .device AT90S8515
  16. .include "8515def.inc"
  17. .equ DISBUF     = $0060          ;显示缓冲区起始地址
  18. .equ TIMEDIS    = $0066          ;时钟时分秒存放单元
  19. .equ XSDBZ      = $0073          ;小数点位标志
  20. .equ DISTBL     = $0f00          ;显示字符编码表起始地址
  21. .equ TIMECTR    = $0010          ;32段时间控制表首址(EEPRON)
  22. .equ TIMECBZ    = $0080          ;控制时间到标志
  23. .cseg
  24. .org $0000
  25.    rjmp RESET
  26. .org $0007
  27.           rjmp TIM0_OVF

  28. ;****主程序***************************************************************************
  29. .def cntms   =r9      
  30. .def hour    =r10
  31. .def minute  =r11                  
  32. .def second  =r12
  33. .def EEdwr   =r16
  34. .def EEawr   =r17
  35. .def EEawrh  =r18
  36. .def EEdrd   =r16  
  37. .def EEard   =r17  
  38. .def EEardh  =r18
  39. .def temp    =r20                  
  40. .def temp1   =r21
  41. .def temp2   =r22
  42. .def temp3   =r23
  43. .def temp4   =r24
  44. .def TIM0INT =r19
  45.             
  46. .org $0020
  47. RESET:     ldi temp,low(ramend) ;设置堆栈指针
  48.     out spl,temp
  49.     ldi temp,high(ramend)
  50.     out sph,temp
  51.            ldi temp,0b11111111  ;设置各口线输入输出状态
  52.            out ddra,temp
  53.            ldi temp,0b00000011
  54.            out ddrb,temp
  55.            ldi temp,0b11111111
  56.            out ddrc,temp
  57.            ldi zl,TIMECBZ
  58.            clr zh
  59.            clr temp
  60.            st y,temp         
  61.            clr r9               ;清各工作寄存器
  62.            clr r10
  63.            clr r11
  64.            clr r12
  65.            clr r13
  66.            clr r14
  67.            clr r15
  68.            clr r16
  69.            clr r17
  70.            clr r18
  71.            clr r19
  72.            clr r25
  73.            ldi temp,$5
  74.            out tccr0,temp      ;T0设置ck/1024分频
  75.            ldi temp,256-195
  76.            out tcnt0,temp      ;装T0时间常数
  77. res1:      ldi temp,$02        ;允许T0中断,并计时
  78.            out timsk,temp
  79.            sei                 ;开中断
  80. res2:      clr r6
  81.            clr r7                          
  82.            sbi PORTb,1
  83.            sbi PORTB,0
  84. res3:      ldi temp,$af
  85. res4:      rcall colodis       ;时钟走时显示
  86.            dec temp
  87.            brne res4         
  88.            sbis pinb,7         ;键扫描
  89.            rjmp PB7M           
  90.            sbis pinb,4         
  91.            rjmp BP4M           ;去参数设置           
  92.            rjmp res3
  93. ;****《系统功能程序》
  94. .org $0080                       ;定义系统功能程序存放区首址
  95. ;****32点打铃器工作程序*************************************************************************  
  96. PB7M:  cbi PORTb,1            ;置运行指示灯亮
  97.        clr r25
  98.        clr r7
  99. GNCX11:ldi r17,TIMECTR        ;首个控制点EEPRON地址
  100.        clr r18
  101.        lsl r25
  102.        lsl r25
  103.        add r17,r25            ;取得EEPRON中控制点地址(Aj=A0+4*j),A=(r17),j=(r25)
  104.        lsr r25
  105.        lsr r25        
  106.        rcall EERead            
  107.        cpi r16,0        
  108.        breq GNCX12             ;r16=(r17)=0为“ON”
  109.        inc r25
  110.        cpi r25,31
  111.        brmi GNCX11      
  112.        rjmp GNCX16
  113. GNCX12:inc r17
  114.        rcall EERead
  115.        cp r16,r10
  116.        brne GNCX13
  117.        inc r17
  118.        rcall EERead
  119.        cp r16,r11
  120.        brne GNCX14
  121.        inc r17
  122.        rcall EERead
  123.        mov r7,r16
  124.        inc r7
  125.        cbi PORTb,0
  126.        rjmp GNCX15
  127. GNCX13:dec r17
  128.        inc r25
  129.        rjmp GNCX11
  130. GNCX14:dec r17
  131.        dec r17
  132.        inc r25
  133.        rjmp GNCX11   
  134. GNCX15:cpi TIM0INT,1
  135.        brne GNCX17
  136.        clr TIM0INT
  137.        dec r7        
  138.        brne GNCX17
  139.        clr r7
  140.        sbi PORTb,0
  141.        rjmp GNCX16
  142. GNCX17:rcall colodis
  143.        sbic pinb,7
  144.        rjmp GNCX15     
  145.        rjmp res2
  146. GNCX16:ldi temp,$5f
  147. GNCX18:rcall colodis
  148.        dec temp
  149.        brne GNCX18            
  150.        sbic pinb,7
  151.        rjmp GNCX11     
  152.        rjmp res2
  153.       
  154. ;****参数设置

  155. BP4M:    ldi temp3,$ff
  156.          ldi temp4,$f
  157. BP4M1:   nop
  158.          rcall colodis
  159.          sbic pinb,4
  160.          rjmp res1
  161.          dec temp3              ;PB4有按下
  162.          brne BP4M1
  163.          inc temp3
  164.          dec temp4
  165.          brne BP4M1
  166.          ldi temp3,$ff         ;超3秒进入
  167.          ldi temp4,$f         
  168. BP4M2:   clr yh
  169.          ldi yl,low(DISBUF)    ;设置显示cloc.
  170.          ldi temp,25
  171.          st y+,temp
  172.          st y+,temp
  173.          ldi temp,18
  174.          st y+,temp
  175.          ldi temp,19
  176.          st y+,temp
  177.          ldi temp,20
  178.          st y+,temp
  179.          ldi temp,18
  180.          st y,temp
  181.          ldi zl,low(XSDBZ)
  182.          clr zh
  183.          ldi temp,0b00100000   ;b0-5对应LED自左到右1-6位的小数点,置“1”在该位置小数点。
  184.          st z,temp
  185.          rcall display
  186.          sbis pinb,5
  187.          rjmp cloc              ;进入时间设置         
  188.          dec temp3
  189.          brne BP4M2
  190.          inc temp3
  191.          dec temp4
  192.          brne BP4M2                     
  193. BP4M3:   ldi temp3,$ff
  194.          ldi temp4,$f
  195. BP4M4:   clr yh
  196.          ldi yl,low(DISBUF)     ;设置显示labor.
  197.          ldi temp,25
  198.          st y+,temp
  199.          ldi temp,19
  200.          st y+,temp
  201.          ldi temp,10
  202.          st y+,temp
  203.          ldi temp,11
  204.          st y+,temp
  205.          ldi temp,20
  206.          st y+,temp
  207.          ldi temp,22
  208.          st y,temp
  209.          ldi zl,low(XSDBZ)
  210.          clr zh
  211.          ldi temp,0b00100000   ;b0-5对应LED自左到右1-6位的小数点,置“1”在该位置小数点。
  212.          st z,temp
  213.          rcall display
  214.          sbis pinb,5
  215.          rjmp GNCS1             ;进入工作参数设置
  216.          dec temp3
  217.          brne BP4M4
  218.          inc temp3
  219.          dec temp4
  220.          brne BP4M4
  221.          sbic pinb,4
  222.          rjmp BP4M
  223.          rjmp res1
  224. ;****时钟调整******************************************************************  
  225. cloc:    clr temp            
  226.          out timsk,temp      ;不许T0中断           
  227.          cli                 ;关中断
  228.          rcall colodis   
  229.          mov temp,r10
  230.          clr temp4
  231.          ldi temp1,20
  232.          ldi temp3,$80
  233. cloc3:   ldi yl,low(DISBUF)
  234.          add yl,temp4
  235.          sbic pinb,5              ;选择时分秒
  236.          rjmp cloc4
  237.          dec temp1
  238.          brne cloc4
  239.          ldi temp1,80
  240.          inc temp4
  241.          inc temp4
  242.          add yl,temp4
  243.          cpi yl,$68
  244.          brmi cloc4
  245.          clr temp4
  246.          ldi yl,low(DISBUF)
  247. cloc4:   nop
  248.          sbic pinb,6              ;调整时分秒值
  249.          rjmp cloc8
  250.          dec temp3
  251.          brne cloc8
  252.          ldi temp3,$20      
  253. cloc5:   cpi yl,$60
  254.          brne cloc6
  255.          inc r10
  256.          mov temp,r10
  257.          cpi temp,24
  258.          brmi cloc8
  259.          clr temp
  260.          clr r10
  261. cloc6:   cpi yl,$62
  262.          brne cloc7
  263.          inc r11
  264.          mov temp,r11
  265.          cpi temp,60
  266.          brmi cloc8
  267.          clr temp
  268.          clr r11
  269. cloc7:   cpi yl,$64
  270.          brne cloc8
  271.          inc r12
  272.          mov temp,r12
  273.          cpi temp,60
  274.          brmi cloc8
  275.          clr temp
  276.          clr r12      
  277. cloc8:   cpi yl,$60
  278.          brne cloc9
  279.          ldi zl,low(XSDBZ)
  280.          clr zh
  281.          ldi temp,0b00000010       ;b0-5对应LED自左到右1-6位的小数点,置“1”在该位置小数点。
  282.          st z,temp
  283.          mov r16,r10        
  284.          rjmp cloc11
  285. cloc9:   cpi yl,$62
  286.          brne cloc10
  287.          ldi zl,low(XSDBZ)
  288.          clr zh
  289.          ldi temp,0b00001000       ;b0-5对应LED自左到右1-6位的小数点,置“1”在该位置小数点。
  290.          st z,temp
  291.          mov r16,r11
  292. cloc10:  cpi yl,$64
  293.          brne cloc11
  294.          ldi zl,low(XSDBZ)
  295.          clr zh
  296.          ldi temp,0b00100000       ;b0-5对应LED自左到右1-6位的小数点,置“1”在该位置小数点。
  297.          st z,temp
  298.          mov r16,r12
  299. cloc11:  rcall bto      
  300.          st y+,r3
  301.          st y,r4
  302.          rcall display
  303.          sbis pinb,4               ;退出
  304.          rjmp cloc12
  305.          rjmp cloc3
  306. cloc12:  ldi temp,$02
  307.          out timsk,temp            ;允许T0中断           
  308.          sei                       ;开中断
  309.          rjmp res1
  310.                               
  311. ;****32点打铃器工作参数调整**********************************************************  
  312. GNCS1:   clr r25                ;首个控制点
  313.          clr r22                ;r22为0显示开关页面,为1显示h-xx页面,为2显示m-xx页面,为3显示c-xx页面
  314.          ldi zl,low(XSDBZ)
  315.          clr zh
  316.          ldi r19,0b00000010
  317.          st z,r19
  318. gncs:    ldi r17,TIMECTR        ;首个控制点EEPRON地址
  319.          clr r18
  320.          ldi yl,low(DISBUF)     ;设置显示缓冲区起始地址
  321.          clr yh
  322.          lsl r25
  323.          lsl r25
  324.          add r17,r25            ;取得EEPRON中控制点地址(Aj=A0+4*j),A=(r17),j=(r25)
  325.          lsr r25
  326.          lsr r25        
  327.          mov r16,r25
  328.          rcall bto
  329.          st y+,r3
  330.          st y+,r4        
  331.          cpi r22,0
  332.          breq kgymxs
  333.          cpi r22,1
  334.          breq hymxs
  335.          cpi r22,2
  336.          breq mymxs
  337.          cpi r22,3
  338.          breq cymxs
  339.          clr r22
  340.          rjmp gncs
  341. kgymxs:  rcall EERead
  342.          cpi r16,0
  343.          brne offxs
  344.          ldi r23,27           ;显示xx.--on
  345.          st y+,r23
  346.          st y+,r23
  347.          ldi r23,20
  348.          st y+,r23
  349.          ldi r23,26
  350.          st y,r23
  351.          rjmp gzcsxs
  352. offxs:   ldi r23,27           ;显示xx.-off
  353.          st y+,r23
  354.          ldi r23,20
  355.          st y+,r23
  356.          ldi r23,15
  357.          st y+,r23
  358.          st y,r23
  359.          rjmp gzcsxs            
  360. hymxs:   ldi r23,28            ;显示xx.h-aa
  361.          st y+,r23
  362.          ldi r23,27
  363.          st y+,r23
  364.          inc r17
  365.          rcall EERead
  366.          rcall bto
  367.          st y+,r3
  368.          st y+,r4
  369.          dec r17
  370.          rjmp gzcsxs
  371. mymxs:   ldi r23,26            ;显示xx.n-aa
  372.          st y+,r23
  373.          ldi r23,27
  374.          st y+,r23
  375.          inc r17
  376.          inc r17
  377.          rcall EERead
  378.          rcall bto
  379.          st y+,r3
  380.          st y+,r4
  381.          dec r17
  382.          dec r17
  383.          rjmp gzcsxs
  384. cymxs:   ldi r23,18            ;显示xx.c-aa
  385.          st y+,r23
  386.          ldi r23,27
  387.          st y+,r23
  388.          inc r17
  389.          inc r17
  390.          inc r17
  391.          rcall EERead
  392.          rcall bto
  393.          st y+,r3
  394.          st y+,r4
  395.          dec r17
  396.          dec r17
  397.          dec r17
  398. gzcsxs:  ldi r23,40
  399.          ldi r24,40
  400. gzcsxs1: rcall display                 
  401.          sbis pinb,5            ;翻页
  402.          rjmp fycz              ;有,去翻页
  403.          sbis pinb,6            ;变值
  404.          rjmp bzcz              ;有,去变值
  405.          sbis pinb,4            ;复位
  406.          rjmp res1              ;有,去复位
  407.          rjmp gncs
  408.          
  409. fycz:    dec r23
  410.          brne gzcsxs1
  411.          rcall EERead
  412.          cpi r16,0
  413.          brne fycz1
  414.          inc r22
  415.          cpi r22,4
  416.          brmi fycz2
  417.          clr r22
  418. fycz1:   inc r25
  419.          cpi r25,32
  420.          brmi fycz2
  421.          clr r25
  422. fycz2:   rjmp gncs               
  423. bzcz:    dec r24
  424.          brne gzcsxs1
  425.          cpi r22,0
  426.          brne bzcz2        
  427. bzcz1:   rcall EERead
  428.          cpi r16,0
  429.          breq bzcz11
  430.          clr r16
  431.          rjmp bzcz12
  432. bzcz11:  ldi r16,1
  433. bzcz12:  rcall EEWrite
  434.          rjmp gncs
  435. bzcz2:   add r17,r22
  436.          rcall EERead
  437.          inc r16
  438.          cpi r22,1
  439.          breq bzcz21
  440.          cpi r16,60
  441.          brmi bzcz22
  442.          clr r16
  443.          rjmp bzcz22
  444. bzcz21:  cpi r16,24
  445.          brmi bzcz22
  446.          clr r16
  447. bzcz22:  rcall EEWrite
  448.          sub r17,r22
  449.          rjmp gncs
  450. ;****显示子程序***********************************************************************
  451. ;*
  452. ;* 功能:将SRAM显示缓冲区存放的数送数码管显示
  453. ;* 入口:DISBUF---显示缓冲区起始地址(SRAM)
  454. ;*       Y--显示缓冲区的指针
  455. ;*       DISTBL---显示字符编码表起始地址(FLASH)
  456. ;*       LEDSXW---LED闪显寄存器位设置
  457. ;*       XSDBZ----小数点设置
  458. ;* 出口:Y--显示缓冲区的指针,指向高地址
  459. ;*
  460. ;****程序段
  461. display: nop
  462.          push temp
  463.          push temp1
  464.          push temp2
  465.          push temp3
  466.          push temp4
  467.          push r6              
  468.          ldi temp1,6
  469.          ldi temp3,0b11011111   
  470.          ldi yl,low(DISBUF)
  471.          ldi yh,high(DISBUF)
  472.          ldi xl,low(XSDBZ)
  473.          clr xh
  474.          ld r6,x
  475. disp1:   ld temp,y+        
  476.          ldi zl,low(DISTBL)
  477.          ldi zh,high(DISTBL)
  478.          add zl,temp
  479.          lsl zl
  480.          rol zh
  481.          lpm         
  482.          lsr r6
  483.          brcc disp2
  484.          ldi temp4,0b10000000
  485.          or r0,temp4
  486. disp2:   out PORTC,r0
  487.          in temp2,PORTA
  488.          ori temp2,0b00111111      
  489.          and temp2,temp3
  490.          out PORTA,temp2
  491.          sec
  492.          ror temp3
  493.          rcall delay
  494.          in temp2,PORTA
  495.          ori temp2,0b00111111
  496.          out PORTA,temp2       ;关显示
  497.          dec temp1
  498.          brne disp1
  499.          pop r6
  500.          pop temp4
  501.          pop temp3
  502.          pop temp2
  503.          pop temp1
  504.          pop temp                              
  505.          ret
  506. ;****时钟显示子程序*********************************************************************
  507. colodis:   push temp
  508.            ldi yl,low(DISBUF)     ;设置显示缓冲区起始地址
  509.            clr yh
  510.            ldi xl,low(TIMEDIS)    ;设置时钟时分秒存放单元
  511.            clr xh
  512.            ldi zl,low(XSDBZ)
  513.            clr zh
  514.            ldi temp,0b00001010    ;b0-5对应LED自左到右1-6位的小数点,置“1”在该位置小数点。
  515.            st z,temp
  516.            rcall ram6ram         
  517.            rcall display
  518.            pop temp
  519.            ret  
  520.          
  521. ;****延时子程序**********************************************************************

  522. delay:  nop          ;延时子程序
  523.         push temp2
  524.         push temp1
  525.   ldi temp2,$ff
  526. lp1:    ldi temp1,$f
  527. lp2: dec temp1
  528. brne lp2
  529. dec temp2
  530. brne lp1
  531.         pop temp1
  532.         pop temp2
  533. ret   ;子程序返回
  534. ;****写EEPRON子程序*********************************************************************
  535. ;*
  536. ;*功能:将EEDWR(r16)内容写入以EEAWR(r18:r17)内容为地址的EEPRON单元内。
  537. ;*
  538. ;****程序段
  539. EEWrite:sbic EECR,EEWE
  540.         rjmp EEWrite
  541.         out  EEARH,EEawrh
  542.         out EEARL,EEawr
  543.         out EEDR,EEdwr
  544.         sbi  EECR,EEMWE
  545.         sbi EECR,EEWE
  546.         ret
  547. ;****读EEPRON子程序*********************************************************************
  548. ;*
  549. ;*功能:从以EEARD(r18:r17)内容为地址的EEPRON单元读区内容送EEDRD(r16)寄存器。
  550. ;*
  551. ;****程序段
  552. EERead: sbic EECR,EEWE
  553. rjmp EERead   
  554. out  EEARH,EEardh
  555. out EEARL,EEard
  556. sbi EECR,EERE
  557.         sbi EECR,EERE
  558. in EEdrd,EEDR
  559. ret
  560. ;****6字节SRAM内容传送子程序************************************************************
  561. ;*
  562. ;* 功能:将SRAM内连续6字节由BLOCK1传送到BLOCK2
  563. ;*       x---欲传送6字节起始地址(SRAM)指针
  564. ;*       y---欲放置6字节起始地址(SRAM)指针
  565. ;*
  566. ;****程序段
  567. ram6ram:push temp1
  568.         push temp2
  569.         ldi temp1,$06      
  570. ramd1:  ld temp2,x+
  571.         st y+,temp2
  572.         dec temp1
  573.         brne ramd1
  574.         pop temp2
  575.         pop temp1
  576.         ret
  577. ;****8位二进制数转3位BCD数子程序********************************************************
  578. ;*
  579. ;*功能:把一个8位无符号二进制数转换为3位BCD码数。
  580. ;*入口:r16---内装8位无符号二进制数。
  581. ;*出口:BCD码放在r2:r3:r4,r2存放百位。
  582. ;*
  583. ;****程序段
  584. bto:      push r16
  585.           clr r2
  586.           clr r3
  587.           clr r4
  588.           rjmp bto2
  589. bto1:     inc r2
  590. bto2:     subi r16,100
  591.           brpl bto1
  592.           ldi temp,100
  593.           add r16,temp
  594.           rjmp bto4
  595. bto3:     inc r3
  596. bto4:     subi r16,10
  597.           brpl bto3
  598.           ldi temp,10
  599.           add r16,temp
  600.           mov r4,r16
  601.           pop r16
  602.           ret
  603. ;****时钟0中断服务程序******************************************************
  604. .org $0bf0
  605. TIM0_OVF:  push temp           
  606.            ldi temp,256-195
  607.            out tcnt0,temp      ;重装T0时间常数
  608.            inc cntms
  609.            mov temp,cntms
  610.            cpi temp,40
  611.            brne timecunt
  612.            clr cntms           
  613.            inc second
  614.            mov temp,second
  615.            cpi temp,60
  616.            brne timecunt
  617.            clr second
  618.            ldi TIM0INT,1
  619.            inc minute  
  620.            mov temp,minute
  621.            cpi temp,60
  622.            brne timecunt
  623.            clr minute
  624.            inc hour
  625.            mov temp,hour
  626.            cpi temp,24
  627.            brne timecunt
  628.            clr hour
  629. timecunt:  ldi xl, low(TIMEDIS)
  630.            clr xh
  631.            mov r16,hour
  632.            rcall bto           
  633.            st x+,r3
  634.            st x+,r4        
  635.            mov r16,minute
  636.            rcall bto
  637.            st x+,r3
  638.            st x+,r4
  639.            mov r16,second
  640.            rcall bto
  641.            st x+,r3
  642.            st x+,r4
  643.            pop temp           
  644.            reti
  645. ;****字形表*****************************************************************                 
  646. .cseg
  647. .org DISTBL
  648. .dw 0x003f,0x0006,0x005b,0x004f,0x0066,0x006d,0x007d,0x0007,0x007f,0x006f
  649. .dw 0x0077,0x007c,0x0039,0x005e,0x0079,0x0071,0x0073,0x0076,0x0058,0x0038
  650. .dw 0x005c,0x0067,0x0050,0x006e,0x0078,0x0000,0x0054,0x0040,0x0074,0x0000
  651. ;*********************************END***************************************
复制代码

举报

回复
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

打开支付宝扫一扫,最高立得1212元红包
搜索

图文热点

更多

社区学堂

更多

客服中心

QQ:187196467 服务时间:周一至周日 8:30-20:30

关注我们

关于我们
关于我们
友情链接
联系我们
帮助中心
网友中心
购买须知
支付方式
服务支持
资源下载
售后服务
定制流程
关注我们
官方微博
官方空间
官方微信
快速回复 返回顶部 返回列表