本实验在proteus软件上模拟完成。
实验器件:20片8X8LED点阵显示屏,10片74LS164移位寄存器,10片74LS273数据锁存器,2片74LS138译码器,1片PIC16F877A单片机。
proteus元件库中中没有16X80点阵显示屏,所以用20片8X8LED点阵屏拼装而成。
10片74LS164移位寄存器和10片74LS273数据锁存器用于传送和保存一行数据。
2片74LS138构成4选16译码器用于行选。
实验截图:
源程序:
list p=16f877A ; list directive to define processor
#include __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ; '__CONFIG' directive is used to embed configuration data within .asm file. ; The lables following the directive are located in the respective .inc file. ; See respective data sheet for additional information on configuration word. ;***** VARIABLE DEFINITIONS w_temp EQU 0x7D ; variable used for context saving status_temp EQU 0x7E ; variable used for context saving pclath_temp EQU 0x7F ; variable used for context saving DELAY_REG EQU 0x20 LINE_NUM EQU 0x21 ;行号 BYTE_NUM EQU 0x22 ;字节号 WORD_NUM EQU 0x23 ;字号 ;字号X32 + 行号X2 + 字节号 得查表偏移量。 BYTE_BIT_COUNT EQU 0x24 ;一个字节的位数,移位时用 SER EQU 0x07 SCK EQU 0x00 RCK EQU 0x01 ;********************************************************************** ORG 0x000 ; processor reset vector nop ; nop required for icd goto main ; go to beginning of program ORG 0x004 ; interrupt vector location retfie ; return from interrupt main ; remaining code goes here BSF STATUS,RP0 CLRF TRISB CLRF TRISC CLRF TRISD BCF STATUS,RP0 CLRF PORTB CLRF PORTC CLRF PORTD CLRF LINE_NUM MAIN_LOOP: CALL LOAD_A_LINE ;加载一行 MOVF LINE_NUM,W ;行选 MOVWF PORTC BSF PORTB,RCK ;将一行数据送入锁存器 NOP NOP BCF PORTB,RCK CALL DELAY ;延时 INCF LINE_NUM ;下一行 BCF LINE_NUM,4 ;一共16行,模16 GOTO MAIN_LOOP ;加载一行 LOAD_A_LINE: CLRF WORD_NUM ;字号清零 LOAD_A_WORD: CLRF BYTE_NUM ;字节号清零 LOAD_A_BYTE: BCF STATUS,C ;清除C标志位,为移位乘2做准备 RLF LINE_NUM,W ;每个字一行占两个字节,所以乘2 ADDWF WORD_NUM,W ;下面WORD_NUM每次加32,不用再乘 ADDWF BYTE_NUM,W ;行号X2 + 字号X32 + 字节号 CALL ENCODE ;查表,取出对应的字节 MOVWF PORTD MOVLW D'8' MOVWF BYTE_BIT_COUNT ;一个字节有8位 LOAD_A_BIT: BSF PORTB,SCK ;将PORTD最高位送入移位寄存器 NOP NOP BCF PORTB,SCK RLF PORTD ;移位,准备将下一位送入移位寄存器 DECFSZ BYTE_BIT_COUNT ;循环8次 GOTO LOAD_A_BIT INCF BYTE_NUM BTFSS BYTE_NUM,1 ;BYTE_NUM==2?一行有两个字节 GOTO LOAD_A_BYTE MOVLW D'32' ADDWF WORD_NUM ;一个字32个字节,每次加32,使用时不用再乘32 MOVF WORD_NUM,W SUBLW D'160' BTFSS STATUS,Z ;WORD_NUM==160?5个字160个字节 GOTO LOAD_A_WORD RETURN ;延时 DELAY: DECFSZ DELAY_REG GOTO DELAY RETURN ENCODE: ADDWF PCL ;黑 DT 0x3F,0xF8,0x21,0x08,0x29,0x28,0x25,0x48,0x25,0x88,0x3F,0xF8,0x01,0x00,0x01,0x00, DT 0x3F,0xF8,0x01,0x00,0xFF,0xFE,0x00,0x00,0x48,0x84,0x44,0x42,0x84,0x42,0x00,0x00 ;龙 DT 0x02,0x00,0x02,0x40,0x02,0x20,0x02,0x20,0x7F,0xFE,0x02,0x80,0x02,0x90,0x02,0x90, DT 0x04,0xA0,0x04,0xC0,0x08,0x80,0x09,0x80,0x12,0x82,0x20,0x82,0x40,0x7E,0x00,0x00 ;江 DT 0x20,0x00,0x10,0x00,0x13,0xFC,0x00,0x40,0x88,0x40,0x48,0x40,0x50,0x40,0x10,0x40, DT 0x10,0x40,0x20,0x40,0xE0,0x40,0x20,0x40,0x20,0x40,0x2F,0xFE,0x20,0x00,0x00,0x00 ;大 DT 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x02,0x80, DT 0x02,0x80,0x02,0x40,0x04,0x40,0x04,0x20,0x08,0x10,0x10,0x18,0x20,0x0E,0x40,0x04 ;学 DT 0x01,0x08,0x10,0x8C,0x0C,0xC8,0x08,0x90,0x7F,0xFE,0x40,0x04,0x8F,0xE8,0x00,0x40, DT 0x00,0x80,0x7F,0xFE,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x02,0x80,0x01,0x00 END ; directive 'end of program'
上一篇:PIC单片机之TIME2
下一篇:PIC单片机CONFIG说明
设计资源 培训 开发板 精华推荐
- LT1172CN8、1.25A 外部限流器的典型应用
- DM163015,基于CAN和LIN收发器的PICDEM CAN-LIN 3演示板
- MAXREFDES1015:采用MAX5971B,元件最少的PSE控制器,支持检测IEEE 802.3af/at设备
- LT5526 高线性度、低功率下变频混频器的典型应用
- 电平灯
- TRK-MPC5604P: MPC5604P StarterTRAK (开发套件)
- SL2.1A升级版(已经测试,含3D打印外壳STL,放心打样)
- 使用 NXP Semiconductors 的 MC9S08MM128VLK 的参考设计
- 基于合宙AIR103主控的加热台
- 使用 Infineon Technologies AG 的 OMR7812NH 的参考设计