Compare commits

...

2 Commits

Author SHA1 Message Date
9f086db4a9 Removed ports.c 2024-05-04 19:58:49 +02:00
284802b283 Moved main to clkgen 2024-05-04 19:39:11 +02:00
3 changed files with 338 additions and 191 deletions

View File

@ -12,22 +12,18 @@ FLASHFILE ?= main.ihx
SYSCLK ?= 12000
CFLAGS ?= -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY
LIBSRC = ports.c adc.c setpin_lo.c setpin_hi.c setpin.c ss_display.c stc15_configure_pin.c
LIBSRC = adc.c setpin_lo.c setpin_hi.c setpin.c ss_display.c stc15_configure_pin.c
LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC))
LIBNAME=mctools.lib
PRGSRC = main.c
PRGSRC = clkgen.c
PRGOBJ =$(patsubst %.c,%.rel, $(PRGSRC))
$(FLASHFILE): $(LIBNAME) $(PRGOBJ)
$(SDCC) -o $(FLASHFILE) $(SDCCOPTS) $(SDCCREV) $(CFLAGS) $(PRGOBJ) $(LIBNAME)
#// @ tail -n 5 build/main.mem | head -n 2
#// @ tail -n 1 build/main.mem
# cp build/$@.ihx $@.hex
$(LIBNAME): $(LIBOBJ)

336
clkgen.c Normal file
View File

@ -0,0 +1,336 @@
#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/10000)
#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 uint16_t pulse=0;
#define PULSE_LEN 250;
static uint8_t single_step=1;
static uint8_t single_step_count=0;
static uint8_t speed=40;
static uint8_t disp_nr=25;
#define MYSW1 P2_7
#define MYSW2 P1_0
#define MYSW3 P1_1
static void handle_switches()
{
static uint8_t lastsw1=1;
static uint8_t lastsw2=1;
static uint8_t lastsw3=1;
if (lastsw3 != MYSW3){
lastsw3=MYSW3;
if(!lastsw3){
if (!single_step){
single_step=1;
return;
}
if(pulse==0){
pulse=PULSE_LEN;
}
}
}
if (lastsw1 != MYSW1){
lastsw1=MYSW1;
if (!lastsw1){
if (single_step){
single_step=0;
return;
}
disp_nr--;
}
}
if (lastsw2 != MYSW2){
lastsw2=MYSW2;
if (!lastsw2) {
if (single_step){
single_step=0;
return;
}
disp_nr++;
}
}
}
static void update_display()
{
uint8_t dig;
static uint8_t pos=0;
switch (pos){
case 0:
P2_5=0;
P2_4=0;
dig=disp_nr/10;
ss_display(sevensegdef,dig);
P2_5=1;
P2_4=0;
break;
case 1:
P2_5=0;
P2_4=0;
dig=disp_nr%10;
ss_display(sevensegdef,dig);
P2_5=0;
P2_4=1;
break;
}
pos++;
if (pos>1)
pos=0;
}
#define COU0 11
#define COU1 1000
static void cou0()
{
static int count=COU0;
if (count--)
return;
count=COU0;
update_display();
handle_switches();
}
static void pulser()
{
if(pulse>0){
P2_6 = 1;
pulse--;
return;
}
P2_6=0;
}
static void cou1()
{
static int ctr = 99;
static int count=COU1;
if (count--)
return;
count=COU1;
if (single_step)
return;
ctr-=disp_nr;
if (ctr <=0){
ctr+=99;
pulse=PULSE_LEN;
}
// if (disp_nr>99)
// disp_nr=0;
}
static void timer0_isr() __interrupt(1) __using (1)
{
EA=0;
cou0();
cou1();
pulser();
EA=1;
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_configure_pin(3,5,PORTMODE_PUSH);
stc15_configure_pin(3,6,PORTMODE_PUSH);
stc15_configure_pin(3,7,PORTMODE_PUSH);
stc15_configure_pin(2,0,PORTMODE_PUSH);
stc15_configure_pin(2,1,PORTMODE_PUSH);
stc15_configure_pin(2,2,PORTMODE_PUSH);
stc15_configure_pin(2,3,PORTMODE_PUSH);
stc15_configure_pin(2,4,PORTMODE_PUSH);
stc15_configure_pin(2,5,PORTMODE_PUSH);
stc15_configure_pin(2,6,PORTMODE_PUSH);
stc15_configure_pin(2,7,PORTMODE_INPUT);
stc15_configure_pin(1,0,PORTMODE_INPUT);
stc15_configure_pin(1,1,PORTMODE_INPUT);
MYSW3=1;
P2_4=1;
P2_5=1;
P2_6=0;
timer0_init();
EA=1;
while(1);
}

185
main.c
View File

@ -1,185 +0,0 @@
#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);
}