;
; TEST-GPIO
;
; FileName: main.S
; Dependencies: p16f1933.h
;
; Processor: PIC16F1933
;
; Complier: GPASM
;
; Company: xx
;
; Author: [email protected]
;
; 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.
nop
nop
bcf PORTC, LCD_PIN_EP ; pull low ep pin.
clrf PORTB
;bcf PORTC, LCD_PIN_RS
;btfsc STK00, 0
;bsf PORTC, LCD_PIN_RS
;bcf PORTC, LCD_PIN_RW
movf TMP09, W
movwf PORTB
bsf PORTC, LCD_PIN_EP ; pull high ep pin.
nop
nop
bcf PORTC, LCD_PIN_EP ; pull low ep pin.
clrf PORTB
bcf PORTC, LCD_PIN_RS
return
_lcd_init
movlw 0x0a
call _delayMs
clrf STK00
bsf STK00, 1 ; no check busy flag.
movlw LCD_CFG_BITS
call _lcd_write
movlw 0x1f
call _delayMs
movlw LCD_CFG_BITS
call _lcd_write
movlw 0x08
call _delayMs
;movlw LCD_CFG_BITS
;call _lcd_write
clrf STK00 ; check busy flag.
movlw LCD_CFG_BITS
call _lcd_write
movlw 0x08
call _delayMs
movlw 0x08 ; lcd_set_display_off
call _lcd_write
movlw 0x01 ; lcd_clear
call _lcd_write
movlw 0x04 ; lcd_set_cur_stop
call _lcd_write
movlw 0x0c ; lcd_set_display_on
call _lcd_write
movlw 0x35
call _delayMs
return
_delayMs
banksel VAR20
movwf VAR20
_00108_DS_
banksel VAR20
decf VAR20,F
movf VAR20,W
btfsc STATUS,2
goto _00111_DS_
movlw 0xfa
movwf VAR21
_00105_DS_
banksel VAR21
decf VAR21,F
movf VAR21,W
btfsc STATUS,2
goto _00108_DS_
goto _00105_DS_
_00111_DS_
return
lcd_display_string1
delayMs1
banksel delayCnt
movwf delayCnt
delayMs_l1
clrw
delayMs_l2
addlw 0x01
btfss STATUS, 0
goto delayMs_l2
decfsz delayCnt, F
goto delayMs_l1
return
delayUs
movwf STK05
incfsz STK05, F
goto $ - 1
return
;----------------------------------------------------------------------
; Program messages
;----------------------------------------------------------------------
string1 retlw 0x57
retlw 0x0a
retlw 0x00
string2 retlw 0x45
retlw 0x0a
retlw 0x00
;----------------------------------------------------------------------
; End of program
;----------------------------------------------------------------------
end