I've tried many variations, but here is the simplest version, which should just set up the display and blank it. I've included the C program and the assembly routine that it calls.
Code: Select all//Global temperature variables go here
unsigned char indoorTemp = 0;
unsigned char outdoorTemp = 0;
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
//Prototypes subroutines:
//-----------------------------------------------------------
void msleep(unsigned long sleeptime);
void updateTemps(void);
void LCDSetup(void);
void writeData(void);
void GetTemp(void);
void main(void) {
EnableInterrupts; /* enable interrupts */
/* include your code here */
msleep(1000); //delay 1 second to wait for power up of LCD display
PTBDD = 0xFF; //set port B bits to be outputs
LCDSetup(); //initialize the LCD
for(;;) {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
void msleep(unsigned long sleeptime){ //Roughly 1msec per count @ 4MHz
unsigned long x;
unsigned long maxtime;
unsigned long y;
maxtime=(unsigned long)sleeptime*11;
for(x=0; x<maxtime;x++){
__RESET_WATCHDOG(); /* feeds the dog */
y=x; //Does nothing except help calibrate timing
}
}
void updateTemps(void){
// unsigned char * inTemp = (unsigned char *)0x67;
// unsigned char * outTemp = (unsigned char *)0x68;
/*modified to match the actual assembly code locations */
unsigned char * inTemp = (unsigned char *)0x66;
unsigned char * outTemp = (unsigned char *)0x67;
//Sample the indoor and outdoor temperatures from the sensors
//and update the LCD screen
//-----------------------------------------------------------
GetTemp(); //changed from getTemp to GetTemp
//Copy the values written by the (assembly code)
indoorTemp = *inTemp;
outdoorTemp = *outTemp;
}
;SUBROUTINE LCDSetup********************************
LCDSetup:
sthx $68 ; save Index Register in $68:$69
sta $65 ; save A in $65
;Wait 200ms to let display initialize
;(Not needed if already >= 200ms since power-on)
bset E, $02 ; Ensure E line is high (inactive)
bclr RS, $02
lda $02
and #$0f
ora #$20
sta $02 ;Set data bus to $2
; bclr E, $02 ; bring E line low
; jsr wait_100us ;Wait 100us
; bset E, $02 ; bring E line high
mov #$28, $70 ;Set "OUTPUT" = 0x28 - Function set - 4-bit, 2-line, 5x8 dots
jsr write_control_Byte
mov #$0C, $70 ; $0C -> $70 - Display ON/OFF - on, cursor off, blinking off
jsr write_control_Byte ; write control char ($70)
mov #$01, $70 ; $01 -> $70 - Clear display
jsr write_control_Byte ; write control char ($70)
jsr delay_2ms ; delay 2ms
mov #$06, $70 ; $06 -> $70 - Entry mode set - cursor moves right, no shift of entire display
jsr write_control_Byte ; write control char ($70)
mov #$02, $70 ; $02 -> $70- Return cursor home
jsr write_control_Byte ; write control char ($70)
jsr delay_2ms
rts
; END SUBROUTINE LCDSetup**************************************
;SUBROUTINE wait_100us
wait_100us:
mov #50, $61
count_100:
;nop
nop
dec $61
bne count_100
sta $1800
rts
;END SUBROUTINE wait_100us************************
; SUBROUTINE write_control_Byte*****************
; control byte to be sent is in address $70
write_control_Byte:
bset E, $02 ; ensure E high
bclr RS, $02 ; clear RS
lda $70
and #$f0 ; clear low nibble
sta $71 ; store high nibble in $71
lda $02 ; PTB -> A
and #$0f ; clear high nibble
ora $71 ; add high nibble from $71 to A
sta $02 ; store result in PTB
bclr E, $02 ; clear E
jsr wait_100us
bset E, $02 ; E is high
lda $70
nsa ; swap nibbles
and #$f0 ; clear low nibble
sta $71 ; store high nibble in $71
lda $02 ; PTB -> A
and #$0f ; clear high nibble
ora $71 ; add high nibble from $71 to A
sta $02 ; store result in PTB
bclr E, $02 ; clear E
jsr wait_100us
bset E, $02
jsr wait_100us
rts
;END SUBROUTINE write_control_Byte*****************
;SUBROUTINE delay_2ms***************
delay_2ms:
mov #20, $60 ;Wait 2ms
wait_2ms:
jsr wait_100us
dec $60
bne wait_2ms
lda $65 ; restore A
ldhx $68 ; restore IX
rts
;END SUBROUTINE delay_2ms