Hardware Reference
In-Depth Information
jsr puts2lcd ; “
ldaa #$C5 ; set LCD cursor position
jsr cmd2lcd ; “
ldx #buf ; output the temperature string
jsr puts2lcd ; “
ldy #2 ; wait for 200 ms
jsr delayby100ms ; “
jmp forever ; continue
; *********************************************************************************
; The following function performs the AD0 configuration.
; *********************************************************************************
openAD0
movb
#$E0,ATD0CTL2
; enable AD0, fast ATD flag clear, stop in wait mode
ldy
#2
jsr
delayby10us
; wait until AD0 is stabilized
movb
#$0A,ATD0CTL3
; perform one A/D conversion
movb
#$25,ATD0CTL4
; set 4 cycles of sample time, set prescaler
divisor to 12
rts
#include
“C:\miniIDE\lcd_util_dragon12.asm”
#include
“c:\miniIDE\delay.asm”
msg1
fcc
“Temperature 5
dc.b
0
spaces
fcc
“ ”
dc.b
0
end
The C language version of the program is as follows:
#include
“c:\egnu091\include\hcs12.h”
#include
“c:\cwHCS12\include\delay.h”
//include delay.c in the project
#include
“c:\cwHCS12\include\convert.h”
//include convert.c in the project
#include
“c:\cwHCS12\include\lcd_util.h”
//include lcd_util.c in the project
void
openAD0(void);
char
buf[8];
char
*msg1 5 “temperature 5 ”;
char
*blanks 5 “ ”;
void
main (void)
{
int
temp1,temp2;
char
sign,fdigit,frem;
char
*ptr;
delayby100ms(2);
/* wait for LCD kit to initialize */
openlcd();
/* configure LCD kit */
openAD0();
/* configure AD0 module */
cmd2lcd(0x80);
/* set cursor to upper left corner */
puts2lcd(msg1);
/* output the message “temperature 5 ” */
while(1) {
sign 5 0;
/* initialize sign to be positive */
ATD0CTL5 5 0x87;
/* start a conversion with result right-justified */
while(!(ATD0STAT0 & SCF));
/* wait until conversion is done */
temp1 5 (ATD0DR0 * 10)/62;
/* integer part of temperature */
Search WWH ::




Custom Search