I'm using the sdcc compiler on a STM8S003F3P6 minimum system development board. It's the sduino core, STM8S103F3 breakout board option in the IDE.
Code: Select all
// For the STM8 board.
// ledPin is same as pin 3, PB5. Notice that the LED is inverted. LOW = on.
// Once I enable the AutoWakeUp interrupt and set the timeout, each halt() is basically a delay()
#define ledPin PB5
const byte messageString[] = " Hello, World! ";
const byte MorseCodeArray[] =
{
0, 0, 0x52, 0, 0, 0, 0, 0x5E, 0x6D, 0x6D, 0, 0, 0x73, 0x61, 0x55, 0x32,
0x3F, 0x2F, 0x27, 0x23, 0x21, 0x20, 0x30, 0x38, 0x3C, 0x3E, 0x78, 0, 0, 0, 0, 0x4C,
0, 5, 0x18, 0x1A, 0xC, 2, 0x12, 0xE, 0x10, 4, 0x17, 0xD, 0x14, 7, 6, 0xF,
0x16, 0x1D, 0xA, 8, 3, 9, 0x11, 0xB, 0x19, 0x1B, 0x1C, 0, 0, 0, 0, 0,
0, 5, 0x18, 0x1A, 0xC, 2, 0x12, 0xE, 0x10, 4, 0x17, 0xD, 0x14, 7, 6, 0xF,
0x16, 0x1D, 0xA, 8, 3, 9, 0x11, 0xB, 0x19, 0x1B, 0x1C, 0, 0, 0, 0, 0
};
void setup()
{
__critical
{
bitSet(GPIOB->CR1, 5); // pinMode(ledPin, OUTPUT_FAST);
bitSet(GPIOB->DDR, 5);
bitSet(GPIOB->CR2, 5);
}
bitSet(GPIOB->ODR, 5); // Turn off LED ***<<<=== This line ***
CLK->ICKR |= 0x20; // REGAH. Shut down power regulator when asleep
FLASH->CR1 |= 8; // Power down flash when in Active Halt mode
AWU->APR = 62; // Set up to wake up in like 1 second
AWU->CSR = 0x10; // Enable AWU interrupt
}
void BlinkDot()
{
bitClear(GPIOB->ODR, 5); // Turn on LED
halt();
bitSet(GPIOB->ODR, 5); // Turn off LED ***<<<=== and This line ***
halt();
}
void BlinkDash()
{
bitClear(GPIOB->ODR, 5); // Turn on LED
halt();
halt();
halt();
bitSet(GPIOB->ODR, 5); // Turn off LED
halt();
}
void EndOfLetter()
{
halt();
halt();
}
void EndOfWord()
{
halt();
halt();
halt();
halt();
}
void BlinkLetterCode(byte LetterCode)
{
if (LetterCode > 1)
{
BlinkLetterCode(LetterCode >> 1);
if (LetterCode & 1)
BlinkDash();
else
BlinkDot();
}
else
EndOfLetter();
}
void loop()
{
int i;
char ch;
AWU->TBR = 9; // like 125 milliSeconds
for (i = 0;; ++i)
{
ch = messageString[i];
if (ch == 0)
break;
if (ch == ' ')
EndOfWord();
else if (ch > ' ' && ch <= 0x7F)
{
ch = MorseCodeArray[ch - 0x20];
BlinkLetterCode(ch);
}
}
AWU->TBR = 14; // like 4 Seconds
halt();
}
void AWU_IRQHandler(void) __interrupt(ITC_IRQ_AWU)
{
AWU->CSR; // Reading AWU_CSR1 register clears the interrupt flag.
}
Code: Select all
.area CODE
; /home/...HelloWorldBlink.ino: 19: void setup()
; -----------------------------------------
; function setup
; -----------------------------------------
_setup:
; /home//...HelloWorldBlink.ino: 26: }
sim
; /home/.../HelloWorldBlink.ino: 23: bitSet(GPIOB->CR1, 5); // pinMode(ledPin, OUTPUT_FAST);
bset 20488, #5
; /home/.../HelloWorldBlink.ino: 24: bitSet(GPIOB->DDR, 5);
bset 20487, #5
; /home/.../HelloWorldBlink.ino: 25: bitSet(GPIOB->CR2, 5);
bset 20489, #5
rim
; /home/.../HelloWorldBlink.ino: 27: bitSet(GPIOB->ODR, 5); // Turn off LED ***<<<=== and This line ***
bset 20485, #5
; /home/.../HelloWorldBlink.ino: 28: CLK->ICKR |= 0x20; // REGAH. Shut down power regulator when asleep
bset 20672, #5
; /home/.../HelloWorldBlink.ino: 29: FLASH->CR1 |= 8; // Power down flash when in Active Halt mode
bset 20570, #3
; /home/.../HelloWorldBlink.ino: 30: AWU->APR = 62; // Set up to wake up in like 1 second
mov 0x50f1+0, #0x3e
; /home/.../HelloWorldBlink.ino: 31: AWU->CSR = 0x10; // Enable AWU interrupt
mov 0x50f0+0, #0x10
; /home/.../HelloWorldBlink.ino: 32: }
ret
; /home/.../HelloWorldBlink.ino: 34: void BlinkDot()
; -----------------------------------------
; function BlinkDot
; -----------------------------------------
_BlinkDot:
; /home/.../HelloWorldBlink.ino: 36: bitClear(GPIOB->ODR, 5); // Turn on LED
ld a, 0x5005
and a, #0xdf
ld 0x5005, a
; /home/.../HelloWorldBlink.ino: 37: halt();
halt
; /home/.../HelloWorldBlink.ino: 38: bitSet(GPIOB->ODR, 5); // Turn off LED ***<<<=== and This line ***
ld a, 0x5005
or a, #0x20
ld 0x5005, a
; /home/.../HelloWorldBlink.ino: 39: halt();
halt
; /home/.../HelloWorldBlink.ino: 40: }
ret