;********************************************************************** ; Esercitazioni PIC18 - Esercitazione # 12 ;********************************************************************** ; test per libreria lcd8l0_18.asm ; Author : afg ; Version : E18_12_00 ; Date : 16/10/2011 ;----------------------------------------------------------------------- ; Descrizione: Il programma invia ad un display LCD a due righe ; un prompt di prova ;----------------------------------------------------------------------- ; Note : Processore PIC18F2321 ; Oscillatore interno a 4 MHz ; senza la necessità di componenti esterni ; Debug con MPLAB IDE e PickKit3 ; Previsto per funzionare con tutti gli enhanced ;************************************************************************ ;======================================================================== ; Impiego pin : ; ---------------- ; 2321 @ 28 pin ; 28 40 ; MCLR/Vpp/RE3 1 1: ; RA0/AN0 2 2: ; RA1/AN1 3 3: ; RA2/AN2/Vref- 4 4: ; RA3/AN3/Vref+ 5 5: ; RA4/T0CKI/C1OUT 6 6: ; RA5/AN4/SS/C2OUT 7 7: ; ; OSC1/CLKI/RA7 9 13: ; OSC2/CLKO/RA6 10 14: Out Clock/4 ; ; RC0/T1OSO/T13CKI 11 15: I/O LCD D0 ; RC1/T1OSI/CCP2 12 16: I/O LCD D1 ; RC2/CCP1 13 17: I/O LCD D2 ; RC3/SCK/SCL 14 18: I/O LCD D3 ; RC4/SDI/SDA 15 23: I/O LCD D4 ; RC5/SDO 16 24: I/O LCD D5 ; RC6/TX/CK 17 25: I/O LCD D6 ; RC7/RX/DT 18 26: I/O LCD D7 ; ; RB0/AN12/INT0/FLT0 21 33: Out LCD E ; RB1/AN10/INT1 22 34: Out LCD RS ; RB2/AN8/INT2 23 35: Out LCD RW ; RB3/AN9/CCP2 24 36: ; RB4/AN11/KBI0 25 37: ; RB5/KBI1/PGM 26 38: ; RB6/KBI2/PGC 27 39: Resetved for debug ; RB7/KBI3/PGD 28 40: Reserved for debug ; ;************************************************************************ ; ; Note : ; ;************************************************************************ LIST P=18F2321 ; Utilizziamo il PIC18F4221 radix dec ; con base decimale per le operazioni ; matematiche #include "P18F2321.INC" ; Include l' header file ;------------------------------------------------------------------------ ; Condizione di compilazione ; Selezionare la modalità richiesta DebugOn equ 1 ; condizioni di debug ;DebugOn equ 0 ; condizioni di release ;------------------------------------------------------------------------ ; Configurazione minima del processore ; CONFIG LVP = OFF ; Single-Supply ICSP disabled CONFIG OSC = INTIO1 ; Osc. interno, port su RA7 e FOSC/4 su RA6 CONFIG MCLRE = ON ; MCLR abilitato CONFIG WDT = OFF ; WDT disabilitato CONFIG BOR = ON ; Brown-out in hardware only CONFIG BORV = 2 ; Soglia BOR 2.7V CONFIG PBADEN = DIG ; Disabilita analogica da PORTB ; Condizione di debug #if DebugOn == 1 ;Background debugger enabled su RB6 e RB7 CONFIG DEBUG = ON ; ICSP/ICD attivo CONFIG PWRT = OFF ; PWRT disabled #else ; condizioni di release CONFIG DEBUG = OFF CONFIG BORV = 2 ; soglia a 2.7V CONFIG PWRT = ON #endif ;======================================================================== ;= DEFINIZIONI = ;======================================================================== ; CLOCK frequency = internal osc. - default a 4 MHz XTAL_FREQ equ 4000000 ; INTIO1 4 MHz; CLOCK equ XTAL_FREQ/4 ; processor clock [Hz] TCYC equ 1000000000/CLOCK ; cycle time [ns] ; ;######################################################################## ;######################################################################## ;======================================================================== ;= AREA ACCESS BANK - RAM = ;======================================================================== ; bank 0 - 128 bytes ; ------------------- CBLOCK 0x00 d1 ; 4 bytes per le routines di tempo d2 d3 nodelay end_Accbank0:0 ; dummy for overrun check ENDC if end_Accbank0 > 0x7F ; check for overrun error "Access Bank 0 space overrun" endif ;======================================================================== ;= I/O definitions = ;======================================================================== ;LCD - linee dati LCDtris equ TRISC ; direzione LCD data port LCDportr equ PORTC ; LCD data port - lettura LCDportw equ LATC ; LCD data port - scrittura ;LCD - linee di controllo #define LCD_RStris TRISB,0 ; RS on portB,0 #define LCD_RSw LATB,0 #define LCD_RSr PORTB,0 #define LCD_RWtris TRISB,1 ; RW on portB,1 #define LCD_RWw LATB,1 #define LCD_RWr PORTB,1 #define LCD_Etris TRISB,2 ; E on portB,2 #define LCD_Ew LATB,2 #define LCD_Er PORTB,2 ;======================================================================== ;= MACRO SET BASE = ;======================================================================== ; driver per oscillatore interno - macros #include C:\PIC\LIBRARY\18F\18FIntClock.asm ;======================================================================== ;= PROGRAMMA = ;======================================================================== ; vettore del reset ; ------------------ ORG 0x00 nop ; per ICD ; porta il clock a 4 MHz m18SetIntClock 4 rcall LCDioini ; inizializa I/O per comando display nop rcall LCDswini ; inizializzazione software dell' LCD clrf nodelay l0 rcall msgl rcall wl m18SetIntClock 8 rcall msgl rcall wl m18SetIntClock 16 rcall msgl rcall wl m18SetIntClock 4 setf nodelay rcall msgl clrf nodelay rcall wl bra l0 ; il cursore è in Home ; scrive sulla prima riga un messaggio ;"microcontroller" msgl rcall Delay05s movlw 'm' rcall LCDWrDat ; scrive e check BF rcall Delay05s movlw 'i' rcall LCDWrDat rcall Delay05s movlw 'c' rcall LCDWrDat rcall Delay05s movlw 'r' rcall LCDWrDat rcall Delay05s movlw 'o' rcall LCDWrDat rcall Delay05s movlw 'c' rcall LCDWrDat rcall Delay05s movlw 'o' rcall LCDWrDat rcall Delay05s movlw 'n' rcall LCDWrDat rcall Delay05s movlw 't' rcall LCDWrDat rcall Delay05s movlw 'r' rcall LCDWrDat rcall Delay05s movlw 'o' rcall LCDWrDat rcall Delay05s movlw 'l' rcall LCDWrDat rcall Delay05s movlw 'l' rcall LCDWrDat rcall Delay05s movlw 'e' rcall LCDWrDat rcall Delay05s movlw 'r' rcall LCDWrDat rcall Delay05s rcall LCDLine2 ; passa alla seconda linea ; scrive sulla seconda riga un messaggio ; " .it" movlw ' ' rcall LCDWrDat ; scrive e check BF movlw ' ' rcall LCDWrDat movlw ' ' rcall LCDWrDat movlw ' ' rcall LCDWrDat movlw ' ' rcall LCDWrDat movlw ' ' rcall LCDWrDat movlw '.' rcall LCDWrDat rcall Delay05s movlw 'i' rcall LCDWrDat rcall Delay05s movlw 't' rcall LCDWrDat return wl rcall Delay05s ; attesa 2 s rcall Delay05s rcall Delay05s rcall Delay05s movlw LCD_CLR ; clear display & Home rcall LCDWrCmd ; scrivi comando rcall Delay05s ; attesa 1 s rcall Delay05s return ;====================================================================== ;---------------------------------------------------------------------- ; driver dell' LCD #include C:\PIC\LIBRARY\18F\LCD8\lcd8bf_l018.asm ;---------------------------------------------------------------------- ;routines di delay ; revisione per PIC18F del codice generato da ; http://www.golovchenko.org/cgi-bin/delay ;--------------------------------------------------------------------- ; Delay05s ; Delay = 0.5 seconds ; Clock frequency = 4 MHz ; Actual delay = 0.5 seconds = 500000 cycles Delay05s ;499994 cycles btfsc nodelay,0 return movlw 0x03 movwf d1 movlw 0x18 movwf d2 movlw 0x02 movwf d3 Dly05_0 decfsz d1, f goto $+6 decfsz d2, f goto $+6 decfsz d3, f goto Dly05_0 ;goto $+4 ;2 cycles return ;4 cycles (including call) ; Delay15ms ; Delay = 0.015 seconds ; Clock frequency = 4 MHz ; Actual delay = 0.015 seconds = 15000 cycles Delay15ms ;14993 cycles movlw 0xB6 movwf d1 movlw 0x0C movwf d2 Dly15_0 decfsz d1, f goto $+6 decfsz d2, f goto Dly15_0 goto $+4 ;3 cycles nop return ;4 cycles (including call) ;--------------------------------------------------------------------- Delay4ms: ; Delay = 0.0041 seconds ; Clock frequency = 4 MHz ; Actual delay = 0.0041 seconds = 4100 cycles Delay4ms ;4093 cycles movlw 0x32 movwf d1 movlw 0x04 movwf d2 Dly4_0 decfsz d1, f goto $+6 decfsz d2, f goto Dly4_0 goto $+4 ;3 cycles nop return ;4 cycles (including call) ;---------------------------------------------------------------------- ; Delay01ms ; Delay = 0.0001 seconds ; Clock frequency = 4 MHz ; Actual delay = 0.0001 seconds = 100 cycles Delay100us ;94 cycles movlw 0x1F movwf d1 Dly01_0 decfsz d1, f goto Dly01_0 goto $+4 ;2 cycles return ;4 cycles (including call) ;---------------------------------------------------------------------- ;---------------------------------------------------------------------- end