Introduction to Microcontroller lab 6

Thread Starter

jiwhun1989

Joined Jun 18, 2013
8
Hello, I am currently taking a summer class for microcontroller 1 and i am having issues doing one of the labs.

The chip we are using is HC(S)12 with CodeWarrior.

Basically our task is write a program to repetitively count from 0 to $FF.
Advance the count every 0.5 second . Display the bytes in the Hex on seven segment display printed circuit board(PCB). using PORTE connections on HCS12.

I got the board to display from 0 to $F (Least sig byte) but part i am having trouble is with displaying MSB after LSB finishes counting upto $F.

Here is what i have so far:

; include derivative specific macros
; INCLUDE 'mc9s12dg128.inc'

;
; include files
include 'constants.inc'
; (a file containing EQUATES of I/O port addresses, bit masks, etc)



;EQUATES
RAM EQU $0800
STACK EQU $0A00


ABSENTRY Start

ORG RAM


Start lds #STACK
ldaa #ALLBIT ;1111 1111 configure all LEDs as outputs
staa DDRA
ldaa #ALLBIT
staa DDRE


Here
ldx #Table ;
ldy #16
ldab #0
Count
ldaa b,x ;b+x =a
staa PORTA
jsr FlashLS
jsr Delay1
stab PORTE
inx ;increment one address in table by 1
dey
bne Count

;Subroutines

Delay1 pshx
psha
ldaa #50 ;delay 0.5 Seconds
Loop ldx #10000
Delay dex
bne Delay
deca
bne Loop
pula
pulx
rts

FlashLS
pshx
psha
bset PORTE,%00000100
clr PORTE
pula
pulx
rts
FlashMS
pshx
psha
bset PORTE,%00001000
clr PORTE
pula
pulx
rts

Table DC.B $FC,$60,$DA,$F2,$66,$B6,$BE,$E0,$FE,$E6,$EE,$3E,$9C,$7A,$9E,$8E

END





;*********************************************************
;* Interrupt Vectors *
;*********************************************************
ORG $FFFE
DC.W Entry ; Reset Vector

Any help will be appreciated
Thanks
 

tshuck

Joined Oct 18, 2012
3,534
You should also post your schematic and use the code tags (click the hash sign-#)....

It would seem that you are meant to multiplex the display, no?
 

tshuck

Joined Oct 18, 2012
3,534
It would seem that you are meant to multiplex the display, no?

i was saying yes to that question
Gotcha...

So how about that schematic? Judging by your decoder table, you have the display hooked up with PORTE<7:1> connected to <a:g>, but I don't want to make assumptions....

I'm not too familiar (as in at all) with this microcontroller, so take what I say with a grain of salt...
 

WBahn

Joined Mar 31, 2012
30,071
I got the board to display from 0 to $F (Least sig byte) but part i am having trouble is with displaying MSB after LSB finishes counting upto $F.
This may or may not be your problem, but each hex digit is a NIBBLE, not a BYTE. Many people can't keep them straight (at least at first) and make a lot of mistakes as a result.

So be sure that you are looking for the next digit to display in the upper nibble of the least significant byte, and not the next byte up.
 

absf

Joined Dec 29, 2010
1,968
Rich (BB code):
Here 
ldx #Table ;
ldy #16
ldab #0 
Count 
ldaa b,x ;b+x =a
staa PORTA
jsr FlashLS
jsr Delay1
stab PORTE
inx ;increment one address in table by 1
dey
bne Count

;Subroutines

Delay1 pshx
psha
ldaa #50 ;delay 0.5 Seconds
Loop ldx #10000
Delay dex
bne Delay
deca
bne Loop
pula
pulx
rts

FlashLS 
pshx
psha
bset PORTE,%00000100
clr PORTE
pula
pulx
rts 
FlashMS 
pshx
psha
bset PORTE,%00001000
clr PORTE
pula
pulx
rts
In your main routine, you called FlashLS to display the least significant digit but you never called the FlashMS even though the subroutine was defined...

strange.

Allen
 
Last edited:

tshuck

Joined Oct 18, 2012
3,534
In addendum to what Allen said, you may want to move your display functionality to a timer interrupt...
 
Last edited:

absf

Joined Dec 29, 2010
1,968
Rich (BB code):
Here 
ldx #Table ;
ldy #16
ldab #0 
Count 
ldaa b,x ;b+x =a
staa PORTA
jsr FlashLS
jsr Delay1
stab PORTE
inx ;increment one address in table by 1
dey
bne Count
You have to put more effort on this main routine.

You need to define a variable that would hold $00-$FF. Select the lower nibble and copy to Acc B then index with the ldaa b,x to display the LSD. Then select the upper nibble and copy to Acc B again then display the MSD. Register Y is mot needed here.

After displaying both LSD and MSD, increment the newly defined variable and repeat the whole process again.

OR you can strengthen the FlashLS and FlashMS subroutines to display its own digit so your main routine would looked something like:

main:
jsr flashLS
jsr delay1
jsr flashMS
jsr delay1
inc variable
bra main

I never used HC12 but I have used HC11. Are the X and Y registers 16 bit registers?

Allen
 
Top