diff --git a/Makefile b/Makefile index 485d678..2fd7769 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ FLASHFILE ?= main.ihx SYSCLK ?= 12000 CFLAGS ?= -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY -LIBSRC = ports.c adc.c +LIBSRC = ports.c adc.c setpin_lo.c setpin_hi.c setpin.c ss_display.c stc15_configure_pin.c LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) diff --git a/main.c b/main.c index 312e725..d9cda25 100644 --- a/main.c +++ b/main.c @@ -10,13 +10,131 @@ #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 count=1; + static int seg = 0; + static int count=500; if (count--) return; - count = 1; + count = 500; ILED = !ILED; + + seg++; + if (seg>9) + seg=0; + + ss_display(sevensegdef,seg); + return; } @@ -33,22 +151,32 @@ void timer0_init() { ET0 = 1; // Enable timer0 interrupt - -/* AUXR &=0x7F; // T0 in 12T mode - TMOD = 0x00; // T0 16-bit-auto-reload - - 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; diff --git a/mctools.h b/mctools.h index 990821a..5926eb8 100644 --- a/mctools.h +++ b/mctools.h @@ -1,6 +1,8 @@ #ifndef MCTOOLS_H_ #define MCTOOLS_H_ +#include + #include "stc15.h" @@ -15,4 +17,59 @@ #define stc15_timer2_set_sysclk1() AUXR |= 0x04; #define stc15_timer2_set_clk_internal() AUXR &=0xF7; // T2 use internal clck +#define stc15_cfg_p2_bidrectional(pin) \ + P2M0 &= (0xFF^(1<> 5; + uint8_t pin = (val>>1) & 0x0F; + if (val &1) + setpin_hi(port,pin); + else + setpin_lo(port,pin); + } +}