;**************************************************************** ;*--------------------------------------------------------------* ;* Data schrijven naar de LCD * ;*--------------------------------------------------------------* ;**************************************************************** ;27/04/2005 LIST P=PIC16F877A #INCLUDE P16F877A.INC __CONFIG _CP_OFF & _DEBUG_OFF & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _BODEN_OFF & _XT_OSC ;Gebruikte Display: HD44780U (2x8 lines LCD) van Hitachi ;---------------------------------------------------------------- ;Definieren van de registers en geheugenplaatsen ;---------------------------------------------------------------- KnoppenTemp EQU PORTA ;Knoppen voor temperatuurregeling LCDControl EQU PORTB ;Poort voor stuursignalen LCD (= outputs) Sensor EQU PORTC ;Alles voor de sensor LCDData EQU PORTD ;Poort voor het doorsturen van characters (= outputs) ResSel EQU H'0004' ;Register Select Signal= pin4 LCD (0 = characters als kommando's aan LCD gegeven ) ReadWrite EQU H'0003' ;Read Write Signal LCD = pin5 LCD (0 = schrijven) Enable EQU H'0002' ;Enable signal LCD = pin6 LCD (initiatie communicatie tss LCD en PIC) TIMER1 EQU H'20' TIMER2 EQU H'21' ;++++++++++++++++++++++++++Begin+++++++++++++++++++++++++++++++++ ORG 0 call InitDisplay ; initialiseren van alle info nodig voor de klok call RESET goto main ;**************************************************************** ; Initialisatie van de PIC - Start ;**************************************************************** RESET bsf STATUS,RP0 ; reg. Bank 1 ;PORTA bcf ADCON1,3 ;Alles van PORTA digitaal zijn bsf ADCON1,2 bsf ADCON1,1 bsf ADCON1,0 movlw B'001111' movwf TRISA ; PortA = input (de niet gebruikte pinnen als output gedefinieerd) ;PORTB movlw B'11000011' ; in-/uitgang definities movwf TRISB ;PORTC movlw B'00010000' ; in-/uitgang definities movwf TRISC ; ;PORTD movlw B'00000000' movwf TRISD ; PortD = output bcf STATUS,RP0 ; reg. Bank 0 ;Alles op 0 zeten ;PORTA movlw B'000000' movwf PORTA ; RA ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;PORTB movlw B'00000000' movwf PORTB ; RB ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;PORTC movlw B'00000000' movwf PORTC ; RC ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;PORTD movlw B'00000000' movwf PORTD ; RD ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;call InitDisplay ;bsf Sensor,TC_CS ;chip afzetten return ;**************************************************************** ; Initialisatie van de PIC - Einde ;**************************************************************** ;--------------------------------------------------------------- ;Procedure die een bepaald character naar de diplay stuurt ;--------------------------------------------------------------- SendData ;Dit is een zeer algemene procedur om data te versturen, zowel voor LCDControl als LCDData movwf LCDData ;De juiste waarde van LCDControl,ResSel hangt dus af van wat je wilt doen, verander deze waarde dus enkel in de hulpprocedures e niet in SendData bcf LCDControl,Enable bsf LCDControl,Enable ;E = 1, we kunnen schrijven naar de display (als R/W = 0, dit betekent schrijven en niet lezen) MOVLW D'255' ;* MOVWF TIMER1 ;* ; DELAY2 MOVLW D'2' ; x msec MOVWF TIMER2 DECFSZ TIMER2,F ;* GOTO $-1 ;* DECFSZ TIMER1,F GOTO DELAY2 RETLW 0 ;-------------------------------------------------------------------------- ;Procedure om alle characters naar de LCD te sturen (1 procedure per char) ;-------------------------------------------------------------------------- Send_A movlw A'A' goto SendData Send_B movlw A'B' goto SendData Send_C movlw A'C' goto SendData Send_D movlw A'D' goto SendData Send_E movlw A'E' goto SendData Send_F movlw A'F' goto SendData Send_G movlw A'G' goto SendData Send_H movlw A'H' goto SendData Send_I movlw A'I' goto SendData Send_J movlw A'J' goto SendData Send_K movlw A'K' goto SendData Send_L movlw A'L' goto SendData Send_M movlw A'M' goto SendData Send_N movlw A'N' goto SendData Send_O movlw A'O' goto SendData Send_P movlw A'P' goto SendData Send_Q movlw A'Q' goto SendData Send_R movlw A'R' goto SendData Send_S movlw A'S' goto SendData Send_T movlw A'T' goto SendData Send_U movlw A'U' goto SendData Send_V movlw A'V' goto SendData Send_W movlw A'W' goto SendData Send_X movlw A'X' goto SendData Send_Y movlw A'Y' goto SendData Send_Z movlw A'Z' goto SendData Send_a movlw A'a' goto SendData Send_b movlw A'b' goto SendData Send_c movlw A'c' goto SendData Send_d movlw A'd' goto SendData Send_e movlw A'e' goto SendData Send_f movlw A'f' goto SendData Send_g movlw A'g' goto SendData Send_h movlw A'h' goto SendData Send_i movlw A'i' goto SendData Send_j movlw A'j' goto SendData Send_k movlw A'k' goto SendData Send_l movlw A'l' goto SendData Send_m movlw A'm' goto SendData Send_n movlw A'n' goto SendData Send_o movlw A'o' goto SendData Send_p movlw A'p' goto SendData Send_q movlw A'q' goto SendData Send_r movlw A'r' goto SendData Send_s movlw A's' goto SendData Send_t movlw A't' goto SendData Send_u movlw A'u' goto SendData Send_v movlw A'v' goto SendData Send_w movlw A'w' goto SendData Send_x movlw A'x' goto SendData Send_y movlw A'y' goto SendData Send_z movlw A'z' goto SendData Send_0 movlw A'0' goto SendData Send_1 movlw A'1' goto SendData Send_2 movlw A'2' goto SendData Send_3 movlw A'3' goto SendData Send_4 movlw A'4' goto SendData Send_5 movlw A'5' goto SendData Send_6 movlw A'6' goto SendData Send_7 movlw A'7' goto SendData Send_8 movlw A'8' goto SendData Send_9 movlw A'9' goto SendData Send_Space movlw A' ' goto SendData Send_Question movlw A'?' goto SendData Send_Point movlw A'.' goto SendData Send_ArrowUp movlw B'00000010' goto SendData Send_ArrowDown movlw B'00000001' goto SendData Send_ArrowKies movlw B'00000000' goto SendData Send_ArrowRight movlw B'01111110' goto SendData Send_ArrowLeft movlw B'01111111' goto SendData Send_Dubbel movlw A':' goto SendData Send_Minus movlw A'-' goto SendData Send_Plus movlw A'+' goto SendData Send_Exclamation movlw A'!' goto SendData Send_Degrees movlw B'11011111' goto SendData Send_En movlw A'&' goto SendData Send_GoHome bcf LCDControl,ResSel movlw B'00000010' ; Go to Home call SendData bsf LCDControl,ResSel return Send_ClearScreen bcf LCDControl,ResSel ;RS = 0, byte aan PORTD zijn nu commando's movlw B'00000001' ; Clear Display call SendData movlw B'00000010' ; Go to Home call SendData bsf LCDControl,ResSel return Send_NextLine bcf LCDControl,ResSel movlw B'11000000' call SendData bsf LCDControl,ResSel return Delay3 CLRWDT MOVLW D'100' MOVWF TIMER1 Delay4 MOVLW D'100' MOVWF TIMER2 DECFSZ TIMER2,F GOTO $-1 DECFSZ TIMER1,F GOTO Delay4 RETLW 0 ;--------------------------------------------------------------- ;Initialisatie van de display ;--------------------------------------------------------------- InitDisplay call Delay3 bcf LCDControl,ReadWrite ;schrijven naar de display bcf LCDControl,ResSel ;RS = 0, we sturen dus commando's naar de display call Delay3 movlw B'00110000' call SendData call Delay3 movlw B'00110000' call SendData call Delay3 movlw B'00110000' call SendData call Delay3 movlw B'00111000' ;Function set call SendData ;2 maal een 8bit line, volgens de datasheet call Delay3 movlw B'00001110' ;Display on/off Control call SendData call Delay3 movlw B'00000110' ;Entry Mode Set call SendData bsf LCDControl,ResSel ;RS = 1, we sturen dus terug characters naar de display call Delay3 return ;---------------------------------------------------------------- ;---------------------------------------------------------------- ;Hoofdprogramma ;---------------------------------------------------------------- ;---------------------------------------------------------------- main call Send_ClearScreen call Send_Space call Send_N ; 02 call Send_e ; 03 call Send_v ; 04 call Send_e ; 05 call Send_r ; 06 call Send_m ; 07 call Send_o call Send_NextLine call Send_r call Send_e main2 goto main2 end