DEVICE 18F452 ;CONFIG INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, LVP_OFF, MCLRE_OFF CONFIG_START OSC = HS ' Oscillator Selection HS OSCS = OFF ' Osc. Switch Enable Disabled PWRT = ON ' Power-up Timer Enabled BOR = OFF ' Brown-out Reset Disabled BORV = 25 ' Brown-out Voltage 2.5V WDT = OFF ' Watchdog Timer Disabled WDTPS = 128 ' Watchdog Postscaler 1:128 CCP2MUX = ON ' CCP2 MUX Enable (RC1) STVR = OFF ' Stack Overflow Reset Disabled LVP = OFF ' Low Voltage ICSP Disabled DEBUG = OFF ' Background Debugger Enable Disabled CP0 = OFF ' Code Protection Block 0 Disabled CP1 = OFF ' Code Protection Block 1 Disabled CP2 = OFF ' Code Protection Block 2 Disabled CP3 = OFF ' Code Protection Block 3 Disabled CPB = OFF ' Boot Block Code Protection Disabled CPD = OFF ' data EEPROM Code Protection Disabled WRT0 = OFF ' Write Protection Block 0 Disabled WRT1 = OFF ' Write Protection Block 1Disabled WRT2 = OFF ' Write Protection Block 2 Disabled WRT3 = OFF ' Write Protection Block 3 Disabled WRTB = OFF ' Boot Block Write Protection Disabled WRTC = OFF ' Configuration Register Write Protection Disabled WRTD = OFF ' data EEPROM Write Protection Disabled EBTR0 = OFF ' Table Read Protection Block 0 Disabled EBTR1 = OFF ' Table Read Protection Block 1 Disabled EBTR2 = OFF ' Table Read Protection Block 2 Disabled EBTR3 = OFF ' Table Read Protection Block 3 Disabled EBTRB = OFF ' Boot Block Table Read Protection Disabled CONFIG_END XTAL = 20 ALL_DIGITAL TRUE ;Alle ingangen digitaal ;bit 76543210 PORTB = %00000000 ;PORTA all lowlevel PORTD = %00000000 ;PORTB all lowlevel TRISB = %00000000 ;PORTA all outputs TRISD = %00000000 ; PORTB_PULLUPS ON ;On-chip pull-up weerstanden actief CLEAR ;clear RAM DIM i AS BYTE ;for next var DIM j AS BYTE ;for next var DIM cl AS BYTE ;for next var DIM cmd AS BYTE DIM statusReg AS BYTE DIM dataOut AS BYTE ;data for writing to LCD DIM dataIn AS BYTE ;data from reading LCD DIM row AS BYTE DIM col AS BYTE DIM kar AS BYTE DIM copy[100] AS BYTE DIM dispStr AS string*20 DIM INVpx AS BYTE ;modify, invert bits DIM SETpx AS BYTE ;modify, set bits DIM CLRpx AS BYTE ;modify, reset bits DIM cX1 AS BYTE ;coordinates x,y p,q DIM cY1 AS BYTE DIM cX2 AS BYTE DIM cY2 AS BYTE DIM rc AS WORD DIM icons AS BYTE 'icon bits on=1 off=0 DIM arrows AS icons.0 'icon1 20 // pijltjes boven elkaar DIM dashes AS icons.1 'icon2A 31 // 2 horiz. streepjes van barcode DIM barcode AS icons.2 'icon2B 32 // barcode DIM batt AS icons.3 'icon3 57 // batterij DIM light AS icons.4 'icon4 69 // sterretje DIM upArrow AS icons.5 'icon5 78 // pijltje UP DIM iconCol[6] AS BYTE 'array with icon columnaddresses iconCol[0]=20:iconCol[1]=31:iconCol[2]=32 iconCol[3]=57:iconCol[4]=69:iconCol[5]=78 SYMBOL UIT = 0 SYMBOL AAN = 1 SYMBOL LAAG = 0 SYMBOL HOOG = 1 SYMBOL A0 = PORTD.7 'A0 SYMBOL Rw = PORTD.6 'READ/write SYMBOL En = PORTD.5 'Enable Digital SYMBOL displayPower = PORTD.4 'displayPower SYMBOL LED = PORTD.3 SYMBOL PBinp = PORTD.2 SYMBOL databus = PORTB arrows=AAN dashes=AAN barcode=AAN batt=AAN light=AAN upArrow=AAN 'Gebaseerd op bascom script van Roland van Leusden sayang@zonnet.nl 'Zie http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&PAGE=viewtopic&t=10688 'Controller: SED1531 'Size: 48 * 100 'Pin layout display: ' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ' GND 5V BL A0 RW E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 '--------------------------- ' Connect BL to GND to turn on backlight ' NOTE: Pinlayout in datasheet is NOT correct ! setup: 'init_lcd DELAYMS 100 cmd=$E2:GOSUB wrCmd ; //reset ; cmd=$A0:GOSUB wrCmd ; //ADC select achterste voren spiegelschrift cmd=$A1:GOSUB wrCmd ; //ADC select achterste voren spiegelschrift cmd=$A2:GOSUB wrCmd ; //set LCD bias cmd=$2C:GOSUB wrCmd ; //power control cmd=$2E:GOSUB wrCmd ; //power control cmd=$2F:GOSUB wrCmd ; //power control cmd=$A6:GOSUB wrCmd ; //normal/reverse (normal) cmd=$8d:GOSUB wrCmd ; //electronic control contrast cmd=$A4:GOSUB wrCmd ; //entire display off niet nodig cmd=$AF:GOSUB wrCmd ; //display on A5? AF is goed! cmd=$40:GOSUB wrCmd ; //start address ;Hoofdprogramma ;wat demo opdrachten batt=UIT:GOSUB wrIcon ;on/off icons row=1:col=1:dispStr="0123456789ABCDEF"+$0 : GOSUB strTOglcd ;zet iets op regel 1 GOSUB graphDemo GOSUB wrLine GOSUB wrCopy ;kopieer regel 1 naar regel 5 kar="A" :row=6:col=10:GOSUB karTOglcd ;schrijf 'A' op regel 6 col 10 GOSUB rdStatus: row=6:col=80: kar=statusReg: GOSUB hexTOglcd ;hex waarde vh statusreg naar rij5 col 80 WHILE 1 = 1 ;forever do nothing WEND END strTOglcd: GOSUB setRowCol FOR j=0 TO 18 IF dispStr[j]=0 THEN j=18:GOTO exitforj ;string data was 00 -> end of str kar=dispStr[j]-32 FOR i=0 TO 4 dataOut=CREAD LCDfont +i +(kar*5) : GOSUB wrData NEXT dataOut=0:GOSUB wrData ;tussen ruimte exitforj: NEXT RETURN karTOglcd: GOSUB setRowCol :dispStr=kar + $0 : GOSUB strTOglcd RETURN hexTOglcd: GOSUB setRowCol : dispStr=STR$(HEX2 kar)+$0: GOSUB strTOglcd RETURN setRowCol: cmd=$B0 + (row - 1):GOSUB wrCmd ;Page = B0h + (row - 1) cmd=$08:GOSUB wrCmd cmd=$00:GOSUB wrCmd setColumn: cmd=$10 + col /16:GOSUB wrCmd ;set column 4 higher bits cmd=$00 + col//16:GOSUB wrCmd ;set column 4 lower bits RETURN wrCmd: databus = cmd ;load command in databus Rw=0:A0=0:En=1:En=0 ' RETURN rdStatus: A0=0 TRISB = %11111111 ;PortB input Rw=1 : En=1 statusReg = databus ;lees databus display, Port B En=0 : Rw=0 TRISB = %00000000 ;PortB terug output RETURN rdData: ; "gewone read data" verhoogt automatisch de column teller! A0=1 TRISB = %11111111 ;PortB input Rw=1 : En=1 dataIn = databus ;lees databus display, Port B En=0 : Rw=0 TRISB = %00000000 ;PortB terug output RETURN rMwData: ;read in read-modify-write mode (extra enable nodig), write verhoogt de columnteller A0=1 TRISB = %11111111 ;PortB input Rw=1 : En=1 :En=0:En=1 ;extra Enable as dummy read dataIn = databus ;lees databus display, Port B En=0 : Rw=0 TRISB = %00000000 ;PortB terug output dataOut=dataIn ;if no bits are set in INV,SET or CLR, dataOut stays unchanged. IF INVpx<>0 THEN dataOut=dataOut ^ INVpx ;bits set in INVpx -> inverted on display,0's unchanged IF SETpx<>0 THEN dataOut=dataOut | SETpx ;bits set in SETpx -> set on display ,0's unchanged IF CLRpx<>0 THEN dataOut=dataOut ^ CLRpx ;bits set in CLRpx -> reset on display ,0's unchanged GOSUB wrData RETURN wrData: databus = dataOut Rw= 0:A0=1 :En=1: En=0 ;set Rw,A0 and pull Enable high for >10 ns. (this takes 200ns@20Mhz) RETURN wrIcon: row=7 ;select icon row FOR i=0 TO 5 ; bit counter for all 6 icons col=iconCol[i] : GOSUB setRowCol ;set icon column dataOut=GETBIT icons,i : GOSUB wrData ; if icon-bit =1 switch icon on, else off NEXT RETURN wrCopy: row=1:col=1: GOSUB setRowCol FOR j=0 TO 99 ;lees regel 1 uit GOSUB rdData :copy[j]=dataIn ;zet data van rij 1 in een array NEXT row=5: col=1:GOSUB setRowCol ;select rij 4 FOR j=0 TO 99 ;schrijf array naar rij 4 dataOut=copy[j] :GOSUB wrData NEXT RETURN graphDemo: row=3:col=1:GOSUB setRowCol FOR j=1 TO 12 ;maak zwarte en witte blokjes van 8x8 pixels FOR i=1 TO 8 IF j//2=0 THEN dataOut=$00 :ELSE: dataOut=$ff : GOSUB wrData NEXT NEXT row=3:col=1:GOSUB setRowCol cmd=$E0:GOSUB wrCmd ; //Start Read-Modify-Write INVpx=%00011000 ;teken een horizontale lijn 2 pixels dik, door bits te inverteren FOR i=1 TO 49:GOSUB rMwData:NEXT cmd=$EE:GOSUB wrCmd ; //End Read-Modify-Write ;DELAYMS 2000 row=3:col=50:GOSUB setRowCol cmd=$E0:GOSUB wrCmd ; //Start Read-Modify-Write SETpx=%0100000 ;teken een horizontale lijn 1 pixel dik, door bits te setten (zwart) FOR i=1 TO 50:GOSUB rMwData:NEXT cmd=$EE:GOSUB wrCmd ; //End Read-Modify-Write ;DELAYMS 2000 row=3:col=50:GOSUB setRowCol cmd=$E0:GOSUB wrCmd ; //Start Read-Modify-Write CLRpx=%00000010 ;teken een horizontale lijn 1 pixel dik, door bits te clearen (wit) FOR i=1 TO 50:GOSUB rMwData:NEXT cmd=$EE:GOSUB wrCmd ; //End Read-Modify-Write ;DELAYMS 2000 RETURN wrLine: ;line x1,y1 - x2,y2 ;werkt nog niet ; cX1=0:cY1=0: cX2=99:cY2=47 FOR col=0 TO 99 ; rc=col*(cX2 -cX1)/(cY2 -cY1) cl=col/2 row=6-(cl/8):cl=7-(cl//8) dataOut=0:SETBIT dataOut,cl GOSUB setRowCol GOSUB wrData ; cmd=$E0:GOSUB wrCmd ; //Start Read-Modify-Write ; INVpx=i ; GOSUB rMwData ; cmd=$EE:GOSUB wrCmd ; //End Read-Modify-Write NEXT RETURN LCDfont: CDATA BYTE $00,$00,$00,$00,$00,_ '(space) $00,$00,$5F,$00,$00,_ '! $00,$07,$00,$07,$00,_ '" $14,$7F,$14,$7F,$14,_ '# $24,$2A,$7F,$2A,$12,_ '$ $23,$13,$08,$64,$62,_ '% $36,$49,$55,$22,$50,_ '& $00,$05,$03,$00,$00,_ '' $00,$1C,$22,$41,$00,_ '( $00,$41,$22,$1C,$00,_ ') $08,$2A,$1C,$2A,$08,_ '* $08,$08,$3E,$08,$08,_ '+ $00,$50,$30,$00,$00,_ ', $08,$08,$08,$08,$08,_ '- $00,$60,$60,$00,$00,_ '. $20,$10,$08,$04,$02,_ '/ $3E,$51,$49,$45,$3E,_ '0 $00,$42,$7F,$40,$00,_ '1 $42,$61,$51,$49,$46,_ '2 $21,$41,$45,$4B,$31,_ '3 $18,$14,$12,$7F,$10,_ '4 $27,$45,$45,$45,$39,_ '5 $3C,$4A,$49,$49,$30,_ '6 $01,$71,$09,$05,$03,_ '7 $36,$49,$49,$49,$36,_ '8 $06,$49,$49,$29,$1E,_ '9 $00,$36,$36,$00,$00,_ ': $00,$56,$36,$00,$00,_ '; $00,$08,$14,$22,$41,_ '< $14,$14,$14,$14,$14,_ '= $41,$22,$14,$08,$00,_ '> $02,$01,$51,$09,$06,_ '? $32,$49,$79,$41,$3E,_ '@ $7E,$11,$11,$11,$7E,_ 'A $7F,$49,$49,$49,$36,_ 'B $3E,$41,$41,$41,$22,_ 'C $7F,$41,$41,$22,$1C,_ 'D $7F,$49,$49,$49,$41,_ 'E $7F,$09,$09,$01,$01,_ 'F $3E,$41,$41,$51,$32,_ 'G $7F,$08,$08,$08,$7F,_ 'H $00,$41,$7F,$41,$00,_ 'I $20,$40,$41,$3F,$01,_ 'J $7F,$08,$14,$22,$41,_ 'K $7F,$40,$40,$40,$40,_ 'L $7F,$02,$04,$02,$7F,_ 'M $7F,$04,$08,$10,$7F,_ 'N $3E,$41,$41,$41,$3E,_ 'O $7F,$09,$09,$09,$06,_ 'P $3E,$41,$51,$21,$5E,_ 'Q $7F,$09,$19,$29,$46,_ 'R $46,$49,$49,$49,$31,_ 'S $01,$01,$7F,$01,$01,_ 'T $3F,$40,$40,$40,$3F,_ 'U $1F,$20,$40,$20,$1F,_ 'V $7F,$20,$18,$20,$7F,_ 'W $63,$14,$08,$14,$63,_ 'X $03,$04,$78,$04,$03,_ 'Y $61,$51,$49,$45,$43,_ 'Z $00,$00,$7F,$41,$41,_ '[ $02,$04,$08,$10,$20,_ '\ $41,$41,$7F,$00,$00,_ '] $04,$02,$01,$02,$04,_ '^ $40,$40,$40,$40,$40,_ '_ $00,$01,$02,$04,$00,_ '` $20,$54,$54,$54,$78,_ 'a $7F,$48,$44,$44,$38,_ 'b $38,$44,$44,$44,$20,_ 'c $38,$44,$44,$48,$7F,_ 'd $38,$54,$54,$54,$18,_ 'e $08,$7E,$09,$01,$02,_ 'f $08,$14,$54,$54,$3C,_ 'g $7F,$08,$04,$04,$78,_ 'h $00,$44,$7D,$40,$00,_ 'i $20,$40,$44,$3D,$00,_ 'j $00,$7F,$10,$28,$44,_ 'k $00,$41,$7F,$40,$00,_ 'l $7C,$04,$18,$04,$78,_ 'm $7C,$08,$04,$04,$78,_ 'n $38,$44,$44,$44,$38,_ 'o $7C,$14,$14,$14,$08,_ 'p $08,$14,$14,$18,$7C,_ 'q $7C,$08,$04,$04,$08,_ 'r $48,$54,$54,$54,$20,_ 's $04,$3F,$44,$40,$20,_ 't $3C,$40,$40,$20,$7C,_ 'u $1C,$20,$40,$20,$1C,_ 'v $3C,$40,$30,$40,$3C,_ 'w $44,$28,$10,$28,$44,_ 'x $0C,$50,$50,$50,$3C,_ 'y $44,$64,$54,$4C,$44,_ 'z 122 $00,$08,$36,$41,$00,_ '{ 123 $00,$00,$7F,$00,$00,_ '| 124 $00,$41,$36,$08,$00,_ '} 125 $08,$08,$2A,$1C,$08,_ '-> 126 $08,$1C,$2A,$08,$08 '<- 127 END