×
单片机 > 单片机程序设计 > 详情

PIC16F1933点亮LCD1602(汇编)

发布时间:2020-08-21 发布时间:
|

;

;       TEST-GPIO

;

;  FileName:        main.S

;  Dependencies:    p16f1933.h

;

;  Processor:       PIC16F1933

;

;  Complier:        GPASM

;

;  Company:         xx

;

;  Author:          Perry.Peng@xx.com

;

;  just do a demonstration of pic16f1933.

;

;  Features used:

;     - GPIO

;     - Timer1

;

;  Description:

;       demo program.

;

;  Notes:

;     -

 

        list p=16f1933, r=dec, f=inhx32, w=0

 

        errorlevel -302   ; suppress message 302 from list file

        include "p16f1933.inc"

 

;        nolist

; ---------------------------------------------------------------------

; Configuration Bits

; ---------------------------------------------------------------------

#define _DEBUG      0xfeff

        __config _CONFIG1, _WDTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _FOSC_INTOSC & _CLKOUTEN_ON

        __config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_ON & _DEBUG

 

;#define LCD_PIN_RS            7

;#define LCD_PIN_RW            6

;#define LCD_PIN_EP            5

 

#define LCD_PIN_RS            3

#define LCD_PIN_RW            4

#define LCD_PIN_EP            5

 

#define LCD_WR_CMD            0

#define LCD_WR_DATA           (1 << LCD_PIN_RS)

#define LCD_RD_CMD            (1 << LCD_PIN_RW)

#define LCD_RD_DATA           ((1 << LCD_PIN_RS) | (1 << LCD_PIN_RW))

 

#define LCD_EP_MASK           (1 << LCD_PIN_EP)

 

#define LCD_CFG_BITS          0x28

 

; Instructs gpasm that it should generate an error if there is any

; use of the given RAM locations.

 

;----------------------------------------------------------------------

; Variables

;----------------------------------------------------------------------

.data udata 0x0020

delayCnt res 1

VAR20 res 1

VAR21 res 1

VAR29 res 1

VAR22 res 1

VAR23 res 1

VAR24 res 1

VAR27 res 1

VAR26 res 1

VAR25 res 1

 

sharebank udata_ovr 0x0070

TMP09 res 1

TMP08 res 1

TMP07 res 1

STK06 res 1

STK05 res 1

STK04 res 1

STK03 res 1

STK02 res 1

STK01 res 1

STK00 res 1

 

;----------------------------------------------------------------------

; Program Memory

;----------------------------------------------------------------------

        org       0x0000              ; Reset vector

        nop

        goto      sysboot

 

        org       0x0004              ; Interrupt Service Routine (ISR)

        retfie

sysboot banksel   OSCCON

; SPLLEN  IRCF3 IRCF2 IRCF1 IRCF0 UNIMP SCS1  SCS0

; 4xPLL    Oscillator Select bits  N/A   1x Internal oscillator

; 4xPLL    1111 = 16MHz HF         N/A   01 timer1 osc

; 4xPLL    1110 = 8MHz or (32MHz)  N/A   00 use CONFIG bits.

; 4xPLL    1101 = 4MHz

; 4xPLL    1100 = 2MHz

; 4xPLL    1011 = 1MHz

; 4xPLL    1010 = 500kHz

; 4xPLL    1001 = 250kHz

; 4xPLL    1000 = 125kHz

; 4xPLL    0111 = 500kHz MF (default)

; 4xPLL    0110 = 250kHz MF

;            ...

; 4xPLL    0011 = 31.25kHz HF

; 4xPLL    0010 = 31.25kHz MF

; 4xPLL    000x = 31kHz LF

 

;        movlw     0xf3                ; 8MHz [x 4xPLL] = 32MHz

        movlw     0x6a                 ; 4MHz

        movwf     OSCCON

        banksel   ANSELA

        clrf      ANSELA

        clrf      ANSELB

        banksel   TRISA

        clrf      TRISA

        bcf       TRISC, LCD_PIN_RS

        bcf       TRISC, LCD_PIN_RW

        bcf       TRISC, LCD_PIN_EP

        banksel   PORTA

        clrf      PORTA

 

;        call      _lcd_init

 

WHILE1

;        banksel   PORTA

;        movf      PORTA, W

;        xorlw     0x20

;        movwf     PORTA

        

        movlw     0x20

        movwf     STK01

        movlw     0x01

        movwf     STK00

        movlw     0x05

        call      _lcd_display_char

 

        movlw     0x81

        clrf      STK00

        call      _lcd_write

 

        movlw     0x33

        bsf       STK00, 0

        call      _lcd_write

 

        goto      WHILE1

        return

 

_lcd_display_char

        movf      STK00, F

        btfss     STATUS, Z

        iorlw     0x40

        iorlw     0x80

        clrf      STK00

        call      _lcd_write

        movf      STK01, W

        bsf       STK00, 0

        call      _lcd_write

        return

 

_lcd_read

        movwf     TMP07

        banksel   TRISB

        movlw     0x0f

        iorwf     TRISB, F

 

        banksel   PORTC

        bcf       PORTC, LCD_PIN_RS

        btfsc     TMP07, 0

        bsf       PORTC, LCD_PIN_RS

        bsf       PORTC, LCD_PIN_RW

        bsf       PORTC, LCD_PIN_EP ; pull high ep pin.

        nop

        swapf     PORTB, W

        bcf       PORTC, LCD_PIN_EP ; pull low ep pin.

        ;bcf       PORTC, LCD_PIN_RW

        andlw     0xf0

        movwf     TMP08

        ;bcf       PORTC, LCD_PIN_RS

        ;btfsc     TMP07, 0

        ;bsf       PORTC, LCD_PIN_RS

        ;bsf       PORTC, LCD_PIN_RW

        bsf       PORTC, LCD_PIN_EP

        nop

        movf      PORTB, W

        bcf       PORTC, LCD_PIN_EP

        bcf       PORTC, LCD_PIN_RW

        andlw     0x0f

        iorwf     TMP08, F

        movf      TMP08, W

        return

 

_lcd_write

        movwf     TMP09

        btfsc     STK00, 1

        goto      $ + 5

 

        clrw

        call      _lcd_read

        btfsc     TMP08, 7

        goto      $ - 3

 

        banksel   PORTB

        clrf      PORTB

        banksel   TRISB

        movlw     0xf0

        andwf     TRISB, F

 

        banksel   PORTC

        bcf       PORTC, LCD_PIN_RS

        btfsc     STK00, 0

        bsf       PORTC, LCD_PIN_RS

        bcf       PORTC, LCD_PIN_RW

        swapf     TMP09, W

        movwf     PORTB

        bsf       PORTC, LCD_PIN_EP ; pull high ep pin.


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
C51 特殊功能寄存器SFR的名称和地址