Skip to content

Instantly share code, notes, and snippets.

@zerog2k
Last active November 18, 2015 14:43
Show Gist options
  • Save zerog2k/f10777fc538f3b6789db to your computer and use it in GitHub Desktop.
Save zerog2k/f10777fc538f3b6789db to your computer and use it in GitHub Desktop.
STC15F204EA sdcc blinky example
#include <stc12.h>
#include <stdint.h>
#include <stdio.h>
/* ------------------------------------------------------------------------- */
/* Printing functions */
/* ------------------------------------------------------------------------- */
#include "./soft_serial/serial.h"
#define printf printf_small
// P0.1 called P5.5 on my board?
#define LED P1_6
/* ------------------------------------------------------------------------- */
int temp = 0;
void _delay_ms(unsigned char ms)
{
// i,j selected for fosc 11.0592MHz, using oscilloscope
// the stc-isp tool gives unusable values (perhaps for C51 vs sdcc?)
// max 255 ms
unsigned char i, j;
do {
i = 4;
j = 200;
do
{
while (--j);
} while (--i);
} while (--ms);
}
const char* startstring = "\n TX Device Ready!\n";
int main()
{
/* init the software uart */
UART_INIT();
/* simple greeting message */
printf("%s", startstring);
LED = 1;
while(1)
{
LED = 0;
_delay_ms(100);
//LED = 1;
//_delay_ms(100);
//LED = 0;
//_delay_ms(100);
LED = 1;
_delay_ms(255);
_delay_ms(255);
printf("counter: %d, CLK_DIV: %x\n", temp, CLK_DIV);
temp++;
//CLR_WDT = 0b1; // service WDT // for some reason - this doesnt work right
WDT_CONTR |= 1 << 4; // clear wdt
}
}
/* ------------------------------------------------------------------------- */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment