Help with my first microcontroller application ever

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with my first microcontroller application ever

1,966 Views
RChapman
Contributor I
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
Posted: Wed Dec 28, 2005 11:04 pm    
 
So I am trying to make an LED blink, and failing at it.

Here is the C code that I have so far.
Code:
#include <MC68HC908KX8.h> void main(void) {   DDRB = 0x01;   TSC = 0x00;   TMODL = 0x00;   TMODH = 0x01;   for(;;) {     __RESET_WATCHDOG();     PTB = 0x01;     while (TSC_TOF == 0);       TSC_TOF = 0;     PTB = 0x01;      while (TSC_TOF == 0);       TSC_TOF = 0;                      }   } 

 
It hangs forever on the fisrt while loop. I don't understand how to use the TMODH and TMODL registers.
 
Posted: Thu Dec 29, 2005 3:20 pm    
 
i think you simply dit not stat the TIM below you see how to init the TIM
(sorry in ASM) but since C is only a better assembler i am shure you will get the idea! Wink
Code:
INI_TIC:                                  ;Initi. OC-Routine         BSET    TRST,TSC             ;TIM-Counter Reset         LDA     TSC                      ;load TIM Status         AND     #%11111000         STA     TSC                      ;PSx = 0         LDA     #$01                     ;load MOD-Register         STA     TMODH         LDA     #$00         STA     TMODL START_TIC:                                ;starts OC         BSET    TOIE,TSC                ;enable TIM TOF-Interrupt (optional)         BCLR    TSTOP,TSC 

 

then your can poll the TOF flag in the TSC register

to clear you have to read TSC first then write 0 to the TOF flag.

Code:
        LDA     TSC                     ;TOF löschen         BCLR    TOF,TSC 

 
Attention: you for HC08 you have to write fist the HI part of a 16 bit register then the Lo part otherwise it will not run!

Saluti
PS. I have uploaded also the EBS08_Qx_CW OS where i use the code abve!
 
Posted: Thu Dec 29, 2005 4:02 pm    
 
G'day,

Quote:
I don't understand how to use the TMODH and TMODL registers.

The 16-bit modulo register setting, represented by TMODH:TMODL, determines the maximum count the timer reaches before overflow occurs, and the count automatically re-starts at zero. For the power-up default value of $FF:FF, this represents 65,536 counts between each overflow condition. For the setting within your program of $01:00, this will represent only 257 counts.

Assuming that you are using the power-up default bus frequency of 1.613 MHz for the 908KX8, you would have a period between timer overflows of about 0.16 milliseconds - somewhat fast to observe the LED blinking.

To provide a flash rate of "hundreds of milliseconds", I would suggest that you leave the modulo setting at the default value, and use a prescale value for the timer greater than 1. For example, a prescale setting of 4 (TSC = 0x02:smileywink: would give a period between overflows of about 160 milliseconds, more appropriate for blinking a LED.

I also see that, within the 'for' loop, you are twice setting PTB0 to a value of 1 (PTB = 0x01:smileywink:, rather than alternating or toggling its state.

I wonder if these are the actual problems, rather than
Quote:
hanging forever on the fisrt while loop
I cannot see an obvious problem with the 'while' loop.

Regards,
 
Posted: Thu Dec 29, 2005 8:04 pm
 
Thanks guys, It works now. Very Happy 
Labels (1)
0 Kudos
0 Replies