

Kod: Markera allt
void main(void)
{
init();
lcdEnable(1);
RA1=0;
RC6=1;
RC7=0;
PORTD=0b01000000; // Y_address
lcdEnable(0);
Delay1KTCYx(100000000);
lcdEnable(1);
RA0=1;
RA1=0;
RC6=1;
RC7=0;
PORTD=0b10111000; //X_address
lcdEnable(0);
Delay1KTCYx(100000000);
lcdEnable(1);
RA1=0;
RC6=1;
RC7=1;
PORTD=0b11000000; //Z_address
lcdEnable(0);
Delay1KTCYx(100000000);
lcdEnable(1);
RA1=1;
RC6=1;
RC7=0;
PORTD=0b11111111; //Data
lcdEnable(0);
Delay1KTCYx(100000000);
//lcdEnable(1);
//RA1=0; // DI
//RC6=1; // CS
//RC7=1;
// PORTD=0x3e; //Display on
//lcdEnable(0);
while(1)
{
}
}
Kod: Markera allt
bcf RST ;Low Reset
bsf CS1 ;Select bank1
bsf CS2 ;Select bank2
bsf RST ;High Reset
call mSdelay
movlw 0x3E ;Display OFF
call cmd_write_GRLCD
movlw 0x40 ;Display Y-adress
call cmd_write_GRLCD
movlw 0xBF ;Display X-adress
call cmd_write_GRLCD
movlw 0xC0 ;Display startline=0
call cmd_write_GRLCD
movlw 0x3F ;Display ON
call cmd_write_GRLCD
Kod: Markera allt
;**********************************************************
list p=18f2221
include "p18f2221.inc"
;**********************************************************
; Exempelprogram för EW12A00FEW
; För PIC18F252
;
; D0-D7 => PORTB
; A0 => PORTC, 0 (data/command select)
; E1 => PORTC, 1 (enable, first controller)
; E2 => PORTC, 2 (enable, second controller)
;
; 5V, LCD-contrast och EL-backling kopplat enl datablad.
;
;**********************************************************
; CONFIG settings
;
config OSC = HS, PWRT = ON, BOR = OFF
config WDT = OFF, LVP = OFF
config DEBUG = OFF, CP0 = OFF, CP1 = OFF
config CPB = OFF, CPD = OFF, WRT0 = OFF
config WRT1 = OFF, WRTB = OFF
config WRTC = OFF, WRTD = OFF, EBTR0 = OFF, EBTR1 = OFF
config EBTRB = OFF
;
;**********************************************************
; Some #defines and EUQ's...
;
#define EW12A00_dataport PORTB
#define EW12A00_A0 LATC, 0
#define EW12A00_E1 LATC, 1
#define EW12A00_E2 LATC, 2
;
;**********************************************************
; Some macros...
;
EW12A00_write_data macro value
movlw value
call EW12A00_data
endm
;
EW12A00_set_page_col macro pag, col
movlw pag
call EW12A00_set_page
movlw col
call EW12A00_set_col
endm
;
;
;**********************************************************
Boot CODE h'0000'
goto Start
;**********************************************************
Main CODE
Start
clrf trisb ; Allt som utgångar...
clrf trisc ;
clrf trisa ;
call delay_1s
call EW12A00_reset
call delay_1s
call EW12A00_set_duty_1_32
call delay_1s
call EW12A00_set_display_on
call delay_1s
call EW12A00_set_static_off
call delay_1s
call EW12A00_set_adc_rev
call delay_1s
call EW12A00_clear
;
EW12A00_set_page_col d'0', d'0'
;
EW12A00_write_data b'01111111' ; "E"
EW12A00_write_data b'01001001'
EW12A00_write_data b'01001001'
EW12A00_write_data b'01001001'
EW12A00_write_data b'01000001'
EW12A00_write_data b'00000000'
;
EW12A00_write_data b'00111111' ; "W"
EW12A00_write_data b'01000000'
EW12A00_write_data b'00111000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'00111111'
EW12A00_write_data b'00000000'
;
EW12A00_write_data b'00000000' ; "1"
EW12A00_write_data b'01000010'
EW12A00_write_data b'01111111'
EW12A00_write_data b'01000000'
EW12A00_write_data b'00000000'
;
EW12A00_write_data b'01000010' ; "2"
EW12A00_write_data b'01100001'
EW12A00_write_data b'01010001'
EW12A00_write_data b'01001001'
EW12A00_write_data b'01000110'
EW12A00_write_data b'00000000'
;
EW12A00_write_data b'01111110' ; "A"
EW12A00_write_data b'00010001'
EW12A00_write_data b'00010001'
EW12A00_write_data b'00010001'
EW12A00_write_data b'01111110'
EW12A00_write_data b'00000000'
;
EW12A00_write_data b'00111110' ; "0"
EW12A00_write_data b'01010001'
EW12A00_write_data b'01001001'
EW12A00_write_data b'01000101'
EW12A00_write_data b'00111110'
EW12A00_write_data b'00000000'
;
EW12A00_write_data b'00111110' ; "0"
EW12A00_write_data b'01010001'
EW12A00_write_data b'01001001'
EW12A00_write_data b'01000101'
EW12A00_write_data b'00111110'
EW12A00_write_data b'00000000'
EW12A00_set_page_col d'1', d'0'
EW12A00_write_data b'01101100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01101100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01101100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01101100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01101100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01001100'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01100000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01100000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01000000'
EW12A00_write_data b'01000000'
EW12A00_set_page_col d'0', d'70'
EW12A00_write_data b'11111111'
EW12A00_write_data b'00000001'
EW12A00_write_data b'00000001'
EW12A00_set_page_col d'1', d'70'
EW12A00_write_data b'11111111'
EW12A00_write_data b'00000001'
EW12A00_write_data b'00000001'
EW12A00_set_page_col d'2', d'70'
EW12A00_write_data b'11111111'
EW12A00_write_data b'00000001'
EW12A00_write_data b'00000001'
EW12A00_set_page_col d'3', d'70'
EW12A00_write_data b'11111111'
EW12A00_write_data b'00000001'
EW12A00_write_data b'00000001'
EW12A00_set_page_col d'1', d'74'
EW12A00_write_data b'11110000'
EW12A00_write_data b'11110000'
EW12A00_set_page_col d'2', d'74'
EW12A00_write_data b'11111111'
EW12A00_write_data b'11111111'
EW12A00_set_page_col d'3', d'74'
EW12A00_write_data b'11111111'
EW12A00_write_data b'11111111'
loop
goto loop ; Once again...
;**********************************************************
; EW12A00xxx subrutines.
;
EW12A00_vars udata_acs
EW12A00_page_addr res 1 ; temp reg for EW12A00_clear
EW12A00_col_addr res 1 ; temp reg for EW12A00_clear
EW12A00_half_flag res 1 ; flag for first second ctrl
EW12A00_col_temp res 1 ; temp reg for EW12A00_set_col
EW12A00_code CODE
;**********************************************************
EW12A00_cmd
; write byte in W as "command" to EW12A00.
; Writes to both controllers...
;
bcf EW12A00_A0 ; "Command" mode
nop
nop
movwf EW12A00_dataport
nop
nop
bsf EW12A00_E1 ; Clock first (left) ctrl.
nop
bsf EW12A00_E2 ; Clock second (right) ctrl.
nop
nop
bcf EW12A00_E1
nop
bcf EW12A00_E2
nop
nop
return
;**********************************************************
EW12A00_data
; write byte in W as "data" to EW12A00.
; Select controller by EW12A00_half_flag
; if h'00' => first controller, left half
; if not h'00' => second controller, right half
;
bsf EW12A00_A0 ; "Data" mode
nop
nop
movwf EW12A00_dataport
nop
nop
tstfsz EW12A00_half_flag
goto EW12A00_write_sec_cont
bsf EW12A00_E1 ; Clock first (left) ctrl.
nop
nop
bcf EW12A00_E1
nop
goto end_of_EW12A00_data
EW12A00_write_sec_cont
bsf EW12A00_E2 ; Clock second (right) ctrl.
nop
nop
bcf EW12A00_E2
nop
end_of_EW12A00_data
return
;**********************************************************
EW12A00_clear
; clear EW12A00...
; Page : 3 => 0
; Column : 121 => 0
;
movlw d'04'
movwf EW12A00_page_addr
clear_page_loop
decf EW12A00_page_addr, f
movf EW12A00_page_addr, w
call EW12A00_set_page
movlw d'122'
movwf EW12A00_col_addr
clear_col_loop
decf EW12A00_col_addr, f
movf EW12A00_col_addr, w
call EW12A00_set_col
EW12A00_write_data h'00'
tstfsz EW12A00_col_addr
goto clear_col_loop
tstfsz EW12A00_page_addr
goto clear_page_loop
return
;**********************************************************
EW12A00_set_col
; column no in W...
; Sets 'EW12A00_half_flag' depending on the column.
;
movwf EW12A00_col_temp
sublw d'60' ; Col > 60 ?
bn EW12A00_set_sec_cont ; Yes
clrf EW12A00_half_flag ; No, first cntl.
movf EW12A00_col_temp, w ; Restore W
goto end_of_EW12A00_set_half
EW12A00_set_sec_cont
setf EW12A00_half_flag ; Second cntl.
movlw d'61' ; Adjust original W value
subwf EW12A00_col_temp, w ; for second cntl...
end_of_EW12A00_set_half
addlw d'19'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_page
; page no in W...
;
; sublw d'3'
iorlw b'10111000'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_adc_forw
movlw b'10100000'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_adc_rev
movlw b'10100001'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_static_on
movlw b'10100101'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_static_off
movlw b'10100100'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_display_on
movlw b'10101111'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_display_off
movlw b'10101110'
call EW12A00_cmd
return
;**********************************************************
EW12A00_reset
movlw b'11100010'
call EW12A00_cmd
return
;**********************************************************
EW12A00_set_duty_1_32
movlw b'11100010'
call EW12A00_cmd
return
;**********************************************************
; Simple delay routine.
; Undefined lenght, probable *not* 1 sec...
;
dly_vars udata_acs
CNT1 res 1
CNT2 res 1
CNT3 res 1
dly_code code
delay_1s
; return
;
movlw 0x01
movwf CNT1
movlw 0x01
movwf CNT2
movlw 0x10
movwf CNT3
dly_loop
decfsz CNT2
goto dly_loop
movlw 0x08
movwf CNT2
decfsz CNT1
goto dly_loop
decfsz CNT3
goto dly_loop
return
end
Kod: Markera allt
clearGRLCD:
call cmd_write_GRLCD
movlw 0x40 ;Display Y-adress
call cmd_write_GRLCD
movlw 0xB8 ;Display X-adress
call cmd_write_GRLCD
movlw 0xC0 ;Display startline=0
call cmd_write_GRLCD
clrf Temp1
clrf Temp2
x_loop:
clrw
call dat_write_GRLCD ;Blanka byten
incf Temp1,1
btfss Temp1,6 ;öka och kolla om 64 annara loopa
goto x_loop
y_loop:
incf Temp2,1 ;Lägg på 1 till page
btfsc Temp2,4 ;Om page > 7 så är det klart
return
movlw 0xb8 ;Lägg på page kommando
addwf Temp2,1
call cmd_write_GRLCD ;Addera för att få rätt page
movlw 0xb8 ;Dra av page kommando
subwf Temp2,1
clrf Temp1 ;Nolla x-räknaren
goto x_loop