mctools/main.c
2024-05-04 02:30:54 +02:00

186 lines
2.5 KiB
C

#include "mctools.h"
#define FOSC 12000000L //system frequency
#define BAUD 9600L //baud-rate
#define DLED P2_6
#define ILED P2_7
#define T0_1MS (65536-FOSC/12/1000)
#define DISP_A P3_5
#define DISP_B P3_6
const uint8_t sevensegdef[][7] = {
// 0
{
(0x35 << 1) | 0,
(0x36 << 1) | 0,
(0x37 << 1) | 0,
(0x20 << 1) | 0,
(0x21 << 1) | 0,
(0x22 << 1) | 0,
(0x23 << 1) | 1,
},
// 1
{
(0x35 << 1) | 1,
(0x36 << 1) | 0,
(0x37 << 1) | 0,
(0x20 << 1) | 1,
(0x21 << 1) | 1,
(0x22 << 1) | 1,
(0x23 << 1) | 1,
},
// 2
{
(0x35 << 1) | 0,
(0x36 << 1) | 0,
(0x37 << 1) | 1,
(0x20 << 1) | 0,
(0x21 << 1) | 0,
(0x22 << 1) | 1,
(0x23 << 1) | 0,
},
// 3
{
(0x35 << 1) | 0,
(0x36 << 1) | 0,
(0x37 << 1) | 0,
(0x20 << 1) | 0,
(0x21 << 1) | 1,
(0x22 << 1) | 1,
(0x23 << 1) | 0,
},
// 4
{
(0x35 << 1) | 1,
(0x36 << 1) | 0,
(0x37 << 1) | 0,
(0x20 << 1) | 1,
(0x21 << 1) | 1,
(0x22 << 1) | 0,
(0x23 << 1) | 0,
},
// 5
{
(0x35 << 1) | 0,
(0x36 << 1) | 1,
(0x37 << 1) | 0,
(0x20 << 1) | 0,
(0x21 << 1) | 1,
(0x22 << 1) | 0,
(0x23 << 1) | 0,
},
// 6
{
(0x35 << 1) | 0,
(0x36 << 1) | 1,
(0x37 << 1) | 0,
(0x20 << 1) | 0,
(0x21 << 1) | 0,
(0x22 << 1) | 0,
(0x23 << 1) | 0,
},
// 7
{
(0x35 << 1) | 0,
(0x36 << 1) | 0,
(0x37 << 1) | 0,
(0x20 << 1) | 1,
(0x21 << 1) | 1,
(0x22 << 1) | 1,
(0x23 << 1) | 1,
},
//8
{
(0x35 << 1) | 0,
(0x36 << 1) | 0,
(0x37 << 1) | 0,
(0x20 << 1) | 0,
(0x21 << 1) | 0,
(0x22 << 1) | 0,
(0x23 << 1) | 0,
},
{
(0x35 << 1) | 0,
(0x36 << 1) | 0,
(0x37 << 1) | 0,
(0x20 << 1) | 0,
(0x21 << 1) | 1,
(0x22 << 1) | 0,
(0x23 << 1) | 0,
}
};
static void timer0_isr() __interrupt(1)
{
static int seg = 0;
static int count=500;
if (count--)
return;
count = 500;
ILED = !ILED;
seg++;
if (seg>9)
seg=0;
ss_display(sevensegdef,seg);
return;
}
void timer0_init() {
stc15_timer0_set_sysclk12();
stc15_timer0_set_mode_16bitauto();
TL0 = T0_1MS; // Initial timer value
TH0 = T0_1MS>>8; // Initial timer value
TF0 = 0; // Clear overflow flag
TR0 = 1; // Timer0 start run
ET0 = 1; // Enable timer0 interrupt
}
void main()
{
uint8_t p = P3;
/* stc15_cfg_p3_opendrain(5);
stc15_cfg_p3_opendrain(6);
stc15_cfg_p3_opendrain(7);
*/
// stc15_configure_pin
// setpin_lo(3,5);
// setpin_hi(3,5);
ss_display(sevensegdef,0);
stc15_cfg_p3_opendrain(6);
// DISP_A = 1;
// DISP_B = 0;
// P3_5 = 0;
// P3 &= (1<<5; // = 0;
ILED=0;
timer0_init();
EA=1;
while(1);
}