Giorgio Demurtas Inserito: 28 aprile 2004 Segnala Inserito: 28 aprile 2004 Sono riuscito a pilotare un diplay LCD con il PIC,vorrei aggiungere l'accensione di due led su RB0 e RB1 (oppure un intero programma che comanda gli I/O rimasti).Ho provato a inserire l'istruzione " bsf PORTB,0 " in diversi punti (dopo bcf PORTB,LCD_RS) ma il led rimane spento...Dove devo mettere di preciso le istruzioni aggiuntive? magari nel punto ci metto una chiamata a una subroutine che contiene il resto del programma.Ecco il listato originale:;******************************************************; PIC Microcontroller By Example; LCD1.ASM: Gestione di un LCD; © 2004, Sergio Tanzilli;****************************************************** PROCESSOR 16F84 RADIX DEC INCLUDE "P16F84.INC";Suppress MPASM warning message 302:;"Register in operand not in bank 0. Ensure that bank bits are correct" ERRORLEVEL -302 __CONFIG 3FF1H;LCD Control linesLCD_RS equ 2 ;Register SelectLCD_E equ 3 ;Enable;LCD data line busLCD_DB4 equ 4 ;LCD data line DB4LCD_DB5 equ 5 ;LCD data line DB5LCD_DB6 equ 6 ;LCD data line DB6LCD_DB7 equ 7 ;LCD data line DB7 ORG 0CHtmpLcdRegister res 2msDelayCounter res 2 ;Reset Vector ORG 00HStart bsf STATUS,RP0 ;Swap to register bank 1 movlw 00011111B ;Set PORTA lines movwf TRISA movlw 11111111B ;Set PORTB lines movwf TRISB bcf PORTB,LCD_DB4 ;Set as output just the LCD's lines bcf PORTB,LCD_DB5 bcf PORTB,LCD_DB6 bcf PORTB,LCD_DB7 bcf PORTB,LCD_E bcf PORTB,LCD_RS bcf STATUS,RP0 ;Swap to register bank 0 ;LCD inizialization call LcdInit ;Locate LCD cursor on row 0, col 0 movlw 10H call LcdLocate ;Shows "CIAO GIORGIO" string on LCD movlw 'C' call LcdSendData movlw 'I' call LcdSendData movlw 'A' call LcdSendData movlw 'O' call LcdSendData movlw ' ' call LcdSendData movlw 'G' call LcdSendData movlw 'I' call LcdSendData movlw 'O' call LcdSendData movlw 'R' call LcdSendData movlw 'G' call LcdSendData movlw 'I' call LcdSendData movlw 'O' call LcdSendData movlw '!' call LcdSendDataforeverLoop goto foreverLoop;**********************************************************************; Delay subroutine;; W = Requested delay time in ms (clock = 4MHz);**********************************************************************msDelay movwf msDelayCounter+1 clrf msDelayCounter+0 ; 1 ms (about) internal loopmsDelayLoop nop decfsz msDelayCounter+0,F goto msDelayLoop nop decfsz msDelayCounter+1,F goto msDelayLoop return;**********************************************************************; Init LCD; This subroutine must be called before each other lcd subroutine;**********************************************************************LcdInit movlw 30 ;Wait 30 ms call msDelay ;**************** ; Reset sequence ;**************** bcf PORTB,LCD_RS ;Set LCD command mode ;Send a reset sequence to LCD bsf PORTB,LCD_DB4 bsf PORTB,LCD_DB5 bcf PORTB,LCD_DB6 bcf PORTB,LCD_DB7 bsf PORTB,LCD_E ;Enables LCD movlw 5 ;Wait 5 ms call msDelay bcf PORTB,LCD_E ;Disables LCD movlw 1 ;Wait 1ms call msDelay bsf PORTB,LCD_E ;Enables LCD movlw 1 ;Wait 1ms call msDelay bcf PORTB,LCD_E ;Disables LCD movlw 1 ;Wait 1ms call msDelay bsf PORTB,LCD_E ;Enables E movlw 1 ;Wait 1ms call msDelay bcf PORTB,LCD_E ;Disables E movlw 1 ;Wait 1ms call msDelay bcf PORTB,LCD_DB4 bsf PORTB,LCD_DB5 bcf PORTB,LCD_DB6 bcf PORTB,LCD_DB7 bsf PORTB,LCD_E ;Enables LCD movlw 1 ;Wait 1ms call msDelay bcf PORTB,LCD_E ;Disabled LCD movlw 1 ;Wait 1ms call msDelay ;Set 4 bit data bus length movlw 28H; call LcdSendCommand ;Entry mode set, increment, no shift movlw 06H; call LcdSendCommand ;Display ON, Curson ON, Blink OFF movlw 0EH call LcdSendCommand ;Clear display call LcdClear return;**********************************************************************; Clear LCD;**********************************************************************LcdClear ;Clear display movlw 01H call LcdSendCommand movlw 2 ;Wait 2 ms call msDelay ;DD RAM address set 1st digit movlw 80H; call LcdSendCommand return;**********************************************************************; Locate cursor on LCD; W = D7-D4 row, D3-D0 col;**********************************************************************LcdLocate movwf tmpLcdRegister+0 movlw 80H movwf tmpLcdRegister+1 movf tmpLcdRegister+0,W andlw 0FH iorwf tmpLcdRegister+1,F btfsc tmpLcdRegister+0,4 bsf tmpLcdRegister+1,6 movf tmpLcdRegister+1,W call LcdSendCommand return;**********************************************************************; Send a data to LCD;**********************************************************************LcdSendData bsf PORTB,LCD_RS call LcdSendByte return;**********************************************************************; Send a command to LCD;**********************************************************************LcdSendCommand bcf PORTB,LCD_RS call LcdSendByte return;**********************************************************************; Send a byte to LCD by 4 bit data bus;**********************************************************************LcdSendByte ;Save value to send movwf tmpLcdRegister ;Send highter four bits bcf PORTB,LCD_DB4 bcf PORTB,LCD_DB5 bcf PORTB,LCD_DB6 bcf PORTB,LCD_DB7 btfsc tmpLcdRegister,4 bsf PORTB,LCD_DB4 btfsc tmpLcdRegister,5 bsf PORTB,LCD_DB5 btfsc tmpLcdRegister,6 bsf PORTB,LCD_DB6 btfsc tmpLcdRegister,7 bsf PORTB,LCD_DB7 bsf PORTB,LCD_E ;Enables LCD movlw 1 ;Wait 1ms call msDelay bcf PORTB,LCD_E ;Disabled LCD movlw 1 ;Wait 1ms call msDelay ;Send lower four bits bcf PORTB,LCD_DB4 bcf PORTB,LCD_DB5 bcf PORTB,LCD_DB6 bcf PORTB,LCD_DB7 btfsc tmpLcdRegister,0 bsf PORTB,LCD_DB4 btfsc tmpLcdRegister,1 bsf PORTB,LCD_DB5 btfsc tmpLcdRegister,2 bsf PORTB,LCD_DB6 btfsc tmpLcdRegister,3 bsf PORTB,LCD_DB7 bsf PORTB,LCD_E ;Enables LCD movlw 1 ;Wait 1ms call msDelay bcf PORTB,LCD_E ;Disabled LCD movlw 1 ;Wait 1ms call msDelay return END
dlgcom Inserita: 28 aprile 2004 Segnala Inserita: 28 aprile 2004 (modificato) Giorgio , nel programma che hai pubblicato c'e' una cosa che sicuramente non va'hai configurato la porta B come tutti ingressi.Penso che neanche il display cosi' funziona.Per comandare display e avere gli altri pin come uscita devi caricare nel TRSIB '00000000'.le istruzioni per accendere il led le puoi mettere dopo l'ultimo carattere che invii al display. movlw '!' call LcdSendData bsf PORTB,0foreverLoop goto foreverLoop Modificato: 28 aprile 2004 da dlgcom
Giorgio Demurtas Inserita: 28 aprile 2004 Autore Segnala Inserita: 28 aprile 2004 Ciao Luca,ho fatto come hai detto ed ha funzionato.0 o 1? mi frega sempre! Però a quanto pere ha fregato anche quelli di fare elettronica (la rivista).Mi sembra piuttosto lunga la programmazone in assembler, in C si semplifica molto la gestione del display?grazie
Giorgio Demurtas Inserita: 28 aprile 2004 Autore Segnala Inserita: 28 aprile 2004 Bella regoletta!Riguardo ad asm o C... mi hai convinto, continuerò con l'assembler... e poi in C, tanto ho visto che +o- in assembler sono sempre le stesse 4 istuzioni combinate in tanti modi diversi.ciao
Messaggi consigliati
Crea un account o accedi per commentare
Devi essere un utente per poter lasciare un commento
Crea un account
Registrati per un nuovo account nella nostra comunità. è facile!
Registra un nuovo accountAccedi
Hai già un account? Accedi qui.
Accedi ora