Hi all,
I'm just starting out in the world of microcontrollers, and the microchip pic was recommended to me, along with 'PIC in practice' book by D W Smith.
I have pretty much covered everything in the book, at times with difficulty due to my minute budget. I have been using the PICkit 2 that comes with a PIC16F690, and many will confirm has hidden problebs, such as recognising switch inputs.
My latest issue is interfacing with an 16x2 LCD alfanumeric display. I have come up with the following .asm code from sources off the internet and also the PIC in practice book.
I am using a Displaytech display from RS- 532-6442
If you could either go through my code, or possibly suggest code for me that I can then play with, and learn from, that would be a great help
Thanks all,
AndyV
I'm just starting out in the world of microcontrollers, and the microchip pic was recommended to me, along with 'PIC in practice' book by D W Smith.
I have pretty much covered everything in the book, at times with difficulty due to my minute budget. I have been using the PICkit 2 that comes with a PIC16F690, and many will confirm has hidden problebs, such as recognising switch inputs.
My latest issue is interfacing with an 16x2 LCD alfanumeric display. I have come up with the following .asm code from sources off the internet and also the PIC in practice book.
I am using a Displaytech display from RS- 532-6442
Rich (BB code):
;*********************************************************
; EQUATES SECTION
#include <p16F690.inc>
DELAY1 EQU 21h
DELAY2 EQU 22h
DISPLAY EQU 23h
COUNT EQU 34h
;**********************************************************************
; Configuration Bits
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
org 0
;*********************************************************
;CONFIGURATION SECTION
Start:
bsf STATUS,RP0 ;select Register Page 1
clrf TRISC ;make make port C outputs
CLRF TRISA
bcf STATUS,RP0 ;back to Register Page 0
bsf STATUS,RP1 ;page 2
clrf ANSEL ;turn off ADC
bcf STATUS,RP1 ;back to page 0
CLRF PORTA
CLRF PORTC
;Display Configuration
MOVLW 03h
MOVWF PORTC ;8 BIT DATA
CALL CLOCK
CALL DELAY
MOVLW 02h
MOVWF PORTC ;CHANGE TO 4BIT
CALL CLOCK
CALL DELAY
MOVLW 0h
MOVWF PORTC ;REPAET COMMAND
CALL DELAY
MOVLW 08h
MOVWF PORTC ;2 LINE DISPLAY
CALL DELAY
MOVLW 0h
MOVWF PORTC ;DISPLAY ON CURSOR OFF
CALL CLOCK
MOVLW 0Ch
MOVWF PORTC
CALL CLOCK
CALL DELAY
MOVLW 0h
MOVWF PORTC ;INCREMENT CURSOR
CALL CLOCK
MOVLW 6h
MOVWF PORTC
CALL CLOCK
MOVLW .8
MOVWF DISPLAY
;*********************************************************
;Program starts now.
HELLO_WORLD
CALL CLRDISP
CLRF PORTA
MOVLW 8h ;CURSOR AT TOP LEFT,80h
MOVWF PORTC
CALL CLOCK
MOVLW 0h
MOVWF PORTC
CALL CLOCK
BSF PORTA,0
CALL H
CALL DELAY
CALL E
CALL DELAY
CALL L
CALL DELAY
CALL L
CALL DELAY
CALL O
CALL DELAY
CALL GAP
CALL DELAY
CALL W
CALL DELAY
CALL O
CALL DELAY
CALL R
CALL DELAY
CALL L
CALL DELAY
CALL D
CALL DELAY
CALL DELAY3S
GOTO HELLO_WORLD
;*********************************************************
;SUBROUTINE SECTION.
;1MS DELAY
DELAY
DECFSZ DELAY1,f ; Waste time.
GOTO DELAY ; The Inner loop takes 3 instructions per loop *
256 loopss = 768 instructions
DECFSZ DELAY2,f ; The outer loop takes and additional 3
instructions per lap * 256 loops
GOTO DELAY ; (768+3) * 256 = 197376 instructions / 1M
instructions per second = 0.197 sec.
; call it a two-tenths of a second.
RETLW 0
DELAY1S
MOVLW .10
MOVWF COUNT
LOOP
CALL DELAY
DECFSZ COUNT
GOTO LOOP
RETLW 0
DELAY3S
MOVLW .30
MOVWF COUNT
LOOP1
CALL DELAY
DECFSZ COUNT
GOTO LOOP1
RETLW 0
CLOCK
BSF PORTA,2
NOP
BCF PORTA,2
NOP
RETLW 0
;***********************************************************************
;
;HELLO WORLD
A MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 3h ;First part of byte (31h)
MOVWF PORTC
CALL CLOCK
MOVLW 1h
MOVWF PORTC
CALL CLOCK
RETLW 0
H MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 3h ;First part of byte (38h)
MOVWF PORTC
CALL CLOCK
MOVLW 8h
MOVWF PORTC
CALL CLOCK
RETLW 0
E MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 3h ;First part of byte (35h)
MOVWF PORTC
CALL CLOCK
MOVLW 5h
MOVWF PORTC
CALL CLOCK
RETLW 0
L MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 3h ;First part of byte (3Ch)
MOVWF PORTC
CALL CLOCK
MOVLW 0Ch
MOVWF PORTC
CALL CLOCK
RETLW 0
O MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 3h ;First part of byte (3Fh)
MOVWF PORTC
CALL CLOCK
MOVLW 0Fh
MOVWF PORTC
CALL CLOCK
RETLW 0
WW MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 4h ;First part of byte (47h)
MOVWF PORTC
CALL CLOCK
MOVLW 7h
MOVWF PORTC
CALL CLOCK
RETLW 0
RR MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 4h ;First part of byte (42h)
MOVWF PORTC
CALL CLOCK
MOVLW 2h
MOVWF PORTC
CALL CLOCK
RETLW 0
DD MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 3h ;First part of byte (32h)
MOVWF PORTC
CALL CLOCK
MOVLW 4h
MOVWF PORTC
CALL CLOCK
RETLW 0
GAP MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 1h ;First part of byte (10h)
MOVWF PORTC
CALL CLOCK
MOVLW 0h
MOVWF PORTC
CALL CLOCK
RETLW 0
CLRDISP CLRF PORTA
MOVLW .1 ;Enables Display
MOVWF PORTA
MOVLW 0h ;First part of byte (01h)
MOVWF PORTC
CALL CLOCK
MOVLW 1h
MOVWF PORTC
CALL CLOCK
RETLW 0
END
Thanks all,
AndyV
Last edited: