add buttons for voltmeters

This commit is contained in:
eddyem
2015-04-19 23:23:40 +03:00
parent f5bd901e9e
commit 8cde19f5b1
26 changed files with 3620 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
NAME=testproj
SDCC=sdcc
CCFLAGS=-DSTM8S003 -I../ -I../../ -I/usr/share/sdcc/include -mstm8 --out-fmt-ihx
LDFLAGS=-mstm8 --out-fmt-ihx -lstm8
FLASHFLAGS=-cstlinkv2 -pstm8s003
SRC=$(wildcard *.c)
OBJ=$(SRC:%.c=%.rel)
TRASH=$(OBJ) $(SRC:%.c=%.rst) $(SRC:%.c=%.asm) $(SRC:%.c=%.lst)
TRASH+=$(SRC:%.c=%.sym) $(NAME).lk $(NAME).map
INDEPENDENT_HEADERS=../stm8l.h Makefile
all: $(NAME).ihx
$(SRC) : %.c : %.h $(INDEPENDENT_HEADERS)
@touch $@
%.h: ;
clean:
rm -f $(TRASH)
load: $(NAME).ihx
stm8flash $(FLASHFLAGS) -w $(NAME).ihx
%.rel: %.c
$(SDCC) $(CCFLAGS) -c $<
$(NAME).ihx: $(OBJ)
$(SDCC) $(LDFLAGS) $(OBJ) -o $(NAME).ihx
.PHONY: all

View File

@@ -0,0 +1,149 @@
/*
* interrupts.c
*
* Copyright 2015 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "stm8l.h"
#include "interrupts.h"
// Top Level Interrupt
INTERRUPT_HANDLER(TLI_IRQHandler, 0){}
// Auto Wake Up Interrupt
INTERRUPT_HANDLER(AWU_IRQHandler, 1){}
// Clock Controller Interrupt
INTERRUPT_HANDLER(CLK_IRQHandler, 2){}
// External Interrupt PORTA
INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3){}
// External Interrupt PORTB
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4){}
// External Interrupt PORTC
INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5){}
// External Interrupt PORTD
INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6){}
// External Interrupt PORTE
INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7){}
#ifdef STM8S903
// External Interrupt PORTF
INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler, 8){}
#endif // STM8S903
#if defined (STM8S208) || defined (STM8AF52Ax)
// CAN RX Interrupt routine.
INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8){}
// CAN TX Interrupt routine.
INTERRUPT_HANDLER(CAN_TX_IRQHandler, 9){}
#endif // STM8S208 || STM8AF52Ax
// SPI Interrupt routine.
INTERRUPT_HANDLER(SPI_IRQHandler, 10){}
// Timer1 Update/Overflow/Trigger/Break Interrupt
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11){
if(TIM1_SR1 & TIM_SR1_UIF){ // update interrupt
Global_time++; // increase timer
}
TIM1_SR1 = 0; // clear all interrupt flags
}
// Timer1 Capture/Compare Interrupt routine.
INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12){}
#ifdef STM8S903
// Timer5 Update/Overflow/Break/Trigger Interrupt
INTERRUPT_HANDLER(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13){}
// Timer5 Capture/Compare Interrupt
INTERRUPT_HANDLER(TIM5_CAP_COM_IRQHandler, 14){}
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
// Timer2 Update/Overflow/Break Interrupt
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13){}
// Timer2 Capture/Compare Interrupt
// process soft I2C
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14){
}
#endif // STM8S903
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \
defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x)
// Timer3 Update/Overflow/Break Interrupt
INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15){}
// Timer3 Capture/Compare Interrupt
INTERRUPT_HANDLER(TIM3_CAP_COM_IRQHandler, 16){}
#endif // STM8S208, STM8S207 or STM8S105 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \
defined(STM8S003) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903)
// UART1 TX Interrupt
INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17){}
// UART1 RX Interrupt
INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18){}
#endif // STM8S208 or STM8S207 or STM8S103 or STM8S903 or STM8AF62Ax or STM8AF52Ax
// I2C Interrupt
INTERRUPT_HANDLER(I2C_IRQHandler, 19){}
#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x)
// UART2 TX interrupt
INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20){}
// UART2 RX interrupt
INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21){}
#endif // STM8S105 or STM8AF626x
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// UART3 TX interrupt
INTERRUPT_HANDLER(UART3_TX_IRQHandler, 20){}
// UART3 RX interrupt
INTERRUPT_HANDLER(UART3_RX_IRQHandler, 21){}
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// ADC2 interrupt
INTERRUPT_HANDLER(ADC2_IRQHandler, 22){}
#else
// ADC1 interrupt
INTERRUPT_HANDLER(ADC1_IRQHandler, 22){
}
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#ifdef STM8S903
// Timer6 Update/Overflow/Trigger Interrupt
INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23){}
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF52Ax or STM8AF62Ax or STM8AF626x
// Timer4 Update/Overflow Interrupt
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23){}
#endif // STM8S903
// Eeprom EEC Interrupt
INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24){}

View File

@@ -0,0 +1,148 @@
/*
* interrupts.h
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __INTERRUPTS_H__
#define __INTERRUPTS_H__
#include "stm8l.h"
extern U8 ADC_ready; // flag: data ready
extern U32 Global_time; // global time in ms
extern int ADC_value; // value of last ADC measurement
// Top Level Interrupt
INTERRUPT_DEFINITION(TLI_IRQHandler, 0);
// Auto Wake Up Interrupt
INTERRUPT_DEFINITION(AWU_IRQHandler, 1);
// Clock Controller Interrupt
INTERRUPT_DEFINITION(CLK_IRQHandler, 2);
// External Interrupt PORTA
INTERRUPT_DEFINITION(EXTI_PORTA_IRQHandler, 3);
// External Interrupt PORTB
INTERRUPT_DEFINITION(EXTI_PORTB_IRQHandler, 4);
// External Interrupt PORTC
INTERRUPT_DEFINITION(EXTI_PORTC_IRQHandler, 5);
// External Interrupt PORTD
INTERRUPT_DEFINITION(EXTI_PORTD_IRQHandler, 6);
// External Interrupt PORTE
INTERRUPT_DEFINITION(EXTI_PORTE_IRQHandler, 7);
#ifdef STM8S903
// External Interrupt PORTF
INTERRUPT_DEFINITION(EXTI_PORTF_IRQHandler, 8);
#endif // STM8S903
#if defined (STM8S208) || defined (STM8AF52Ax)
// CAN RX Interrupt routine.
INTERRUPT_DEFINITION(CAN_RX_IRQHandler, 8);
// CAN TX Interrupt routine.
INTERRUPT_DEFINITION(CAN_TX_IRQHandler, 9);
#endif // STM8S208 || STM8AF52Ax
// SPI Interrupt routine.
INTERRUPT_DEFINITION(SPI_IRQHandler, 10);
// Timer1 Update/Overflow/Trigger/Break Interrupt
INTERRUPT_DEFINITION(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11);
// Timer1 Capture/Compare Interrupt routine.
INTERRUPT_DEFINITION(TIM1_CAP_COM_IRQHandler, 12);
#ifdef STM8S903
// Timer5 Update/Overflow/Break/Trigger Interrupt
INTERRUPT_DEFINITION(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13);
// Timer5 Capture/Compare Interrupt
INTERRUPT_DEFINITION(TIM5_CAP_COM_IRQHandler, 14);
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
// Timer2 Update/Overflow/Break Interrupt
INTERRUPT_DEFINITION(TIM2_UPD_OVF_BRK_IRQHandler, 13);
// Timer2 Capture/Compare Interrupt
INTERRUPT_DEFINITION(TIM2_CAP_COM_IRQHandler, 14);
#endif // STM8S903
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \
defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x)
// Timer3 Update/Overflow/Break Interrupt
INTERRUPT_DEFINITION(TIM3_UPD_OVF_BRK_IRQHandler, 15);
// Timer3 Capture/Compare Interrupt
INTERRUPT_DEFINITION(TIM3_CAP_COM_IRQHandler, 16);
#endif // STM8S208, STM8S207 or STM8S105 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \
defined(STM8S003) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903)
// UART1 TX Interrupt
INTERRUPT_DEFINITION(UART1_TX_IRQHandler, 17);
// UART1 RX Interrupt
INTERRUPT_DEFINITION(UART1_RX_IRQHandler, 18);
#endif // STM8S208 or STM8S207 or STM8S103 or STM8S903 or STM8AF62Ax or STM8AF52Ax
// I2C Interrupt
INTERRUPT_DEFINITION(I2C_IRQHandler, 19);
#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x)
// UART2 TX interrupt
INTERRUPT_DEFINITION(UART2_TX_IRQHandler, 20);
// UART2 RX interrupt
INTERRUPT_DEFINITION(UART2_RX_IRQHandler, 21);
#endif // STM8S105 or STM8AF626x
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// UART3 TX interrupt
INTERRUPT_DEFINITION(UART3_TX_IRQHandler, 20);
// UART3 RX interrupt
INTERRUPT_DEFINITION(UART3_RX_IRQHandler, 21);
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// ADC2 interrupt
INTERRUPT_DEFINITION(ADC2_IRQHandler, 22);
#else // STM8S105, STM8S103 or STM8S903 or STM8AF626x
// ADC1 interrupt
INTERRUPT_DEFINITION(ADC1_IRQHandler, 22);
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#ifdef STM8S903
// Timer6 Update/Overflow/Trigger Interrupt
INTERRUPT_DEFINITION(TIM6_UPD_OVF_TRG_IRQHandler, 23);
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF52Ax or STM8AF62Ax or STM8AF626x
// Timer4 Update/Overflow Interrupt
INTERRUPT_DEFINITION(TIM4_UPD_OVF_IRQHandler, 23);
#endif // STM8S903
// Eeprom EEC Interrupt
INTERRUPT_DEFINITION(EEPROM_EEC_IRQHandler, 24);
#endif // __INTERRUPTS_H__

View File

@@ -0,0 +1,258 @@
/*
* led.c
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "stm8l.h"
#include "led.h"
/*
* bits no 7 6 5 4 3 2 1 0
* dec value 128 64 32 16 8 4 2 1
*/
/********** current variant **********/
/*
* One digit: TABLE:
* ***A*** 0 1 2 3 4 5 6 7 8 9 A B C D E F - h
* * * (F) PB4 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0
* F B (B) PB5 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1
* * * (A) PC3 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 1 1
* ***G*** (G) PC7 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0
* * * (C) PD1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0
* E C (DP)PC6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
* * * ** (D) PC5 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 1
* ***D*** *DP* (E) PC4 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0 1 0
* **
*/
/*
* BUTTONS
* DON'T FORGET: PB4 & PB5 are "real open-drain"! They can't be pullup inputs, so
* you should solder resistor 10..47k to appropriate buttons!
* 0 - PB4, 1 - PB5, 2 - PD1, 3..7 - PC3..PC7
* or:
* 0 - F(10), 1 - B(7), 2 - C(4), 3 - A(11), 4 - E(1), 5 - D(2), 6 - DP(3), 7 - G(5)
*/
volatile U8 buttons_state;
static U8 display_buffer[3] = {' ',' ',' '}; // blank by default
static U8 N_current = 0; // current digit to display
/*
* Number of digit on indicator with common anode
* digis 0..2: PA3, PD4, PD5
*/
#define CLEAR_ANODES() do{PD_ODR &= ~(0x30);PA_ODR &= ~(0x08);}while(0)
/************* arrays for ports *************/
// PB, mask: 0x30 (dec: 48), PB4:0x10=16, PB5:0x20=32
// To light up a segment we should setup it as PPout -> this arrays are inverse!
#define PB_BLANK 0x30
static U8 PB_bits[18] = {48,32,32,32,48,16,16,32,48,48,48,16,16,32,16,16,0,16};
// PC, mask: 0xF8 (dec: 248), PC3:0x08=8, PC4:0x10=16, PC5:0x20=32, PC6:0x40=64, PC7:0x80=128
#define PC_BLANK 0xF8
static U8 PC_bits[18] = {56,0,184,168,128,168,184,8,184,168,152,176,56,176,184,152,128,144};
// PD, mask: 0x02, PD1
static U8 PD_bits[18] = {2,2,0,2,2,2,2,2,2,2,2,2,0,2,0,0,0,2};
#define PD_BLANK 0x02
/**
* Initialize ports
* anodes (PA3, PD4, PD5) are push-pull outputs,
* cathodes (PB4, PB5, PD1, PC3..PC7) are ODouts in active mode, pullup inputs in buttons reading and floating inputs in inactive
* PA3, PB4|5, PC3|4|5|6|7, PD1|4|5
*/
void LED_init(){
PA_DDR |= 0x08; PD_DDR |= 0x30; // anodes are PPout, cathodes will be PPout only in active mode
PA_CR1 |= 0x08; PD_CR1 |= 0x30;
// prepare cathodes ODR
PB_ODR &= ~PB_BLANK; PC_ODR &= ~PC_BLANK; PD_ODR &= ~PD_BLANK;
}
/*
********************* GPIO (page 111) ********************
* Px_ODR - Output data register bits
* Px_IDR - Pin input values
* Px_DDR - Data direction bits (1 - output)
* Px_CR1 - DDR=0: 0 - floating, 1 - pull-up input; DDR=1: 0 - pseudo-open-drain, 1 - push-pull output [not for "T"]
* Px_CR2 - DDR=0: 0/1 - EXTI disabled/enabled; DDR=1: 0/1 - 2/10MHz
*
*/
/**
* Show next digit - function calls from main() by some system time value amount
*/
void show_next_digit(){
U8 L = display_buffer[N_current] & 0x7f;
// first turn all off
CLEAR_ANODES();
// convert all cathodes to pullup inputs (CR1 is already in ones)
PB_DDR &= ~PB_BLANK;
PC_DDR &= ~PC_BLANK;
PD_DDR &= ~PD_BLANK;
PB_CR1 |= PB_BLANK;
PC_CR1 |= PC_BLANK;
PD_CR1 |= PD_BLANK;
// process buttons attached to A1 and cathodes
if(N_current == 1){ // first digit was lighten up, now we light second -- check buttons
// now check button states: 0 - PB4, 1 - PB5, 2 - PD1, 3..7 - PC3..PC7
buttons_state =
((PB_IDR & PB_BLANK) >> 4) |
((PD_IDR & PD_BLANK) << 1) |
(PC_IDR & PC_BLANK);
}
// switch all anodes to floating inputs
PA_DDR &= ~0x08; PA_CR1 &= ~0x08;
PD_DDR &= ~0x30; PD_CR1 &= ~0x30;
// turn off pullups of cathodes (also all outputs now will be OD)
PB_CR1 &= ~PB_BLANK;
PC_CR1 &= ~PC_BLANK;
PD_CR1 &= ~PD_BLANK;
// now set spare segments switching them to ODoutputs
if(L < 18){ // letter
PB_DDR |= PB_bits[L];
PC_DDR |= PC_bits[L];
PD_DDR |= PD_bits[L];
}
if(L & 0x80){ // DP
PC_DDR |= GPIO_PIN6;
}
switch(N_current){
case 0:
PA_DDR |= 0x08; // switch to output
PA_CR1 |= 0x08; // push-pull
PA_ODR |= 0x08;
break;
case 1:
PD_DDR |= 0x10;
PD_CR1 |= 0x10;
PD_ODR |= 0x10;
break;
case 2:
PD_DDR |= 0x20;
PD_CR1 |= 0x20;
PD_ODR |= 0x20;
break;
}
if(++N_current > 2) N_current = 0;
}
/**
* fills buffer to display
* @param str - string to display, contains "0..f" for digits, " " for space, "." for DP
* for example: " 1.22" or "h1ab" (something like "0...abc" equivalent to "0.abc"
* register independent!
* any other letter would be omitted
* if NULL - fill buffer with spaces
*/
void set_display_buf(char *str){
U8 B[3];
char ch, M = 0, i;
N_current = 0; // refresh current digit number
// empty buffer
for(i = 0; i < 3; i++)
display_buffer[i] = ' ';
if(!str) return;
i = 0;
for(;(ch = *str) && (i < 3); str++){
M = 0;
if(ch > '/' && ch < ':'){ // digit
M = '0';
}else if(ch > '`' & ch < 'g'){ // a..f
M = 'a' - 10;
}else if(ch > '@' & ch < 'G'){ // A..F
M = 'A' - 10;
}else if(ch == '-'){ // minus
M = '-' - 16;
}else if(ch == 'h'){ // hex
M = 'h' - 17;
}else if(ch == 'H'){ // hex
M = 'H' - 17;
}else if(ch == '.'){ // DP, set it to previous char
if(i == 0){ // word starts from '.' - make a space with point
B[0] = 0xff;
}else{ // set point for previous character
B[i-1] |= 0x80;
}
continue;
}else if(ch != ' '){ // bad character - continue
continue;
}
B[i] = ch - M;
i++;
}
// now make align to right
ch = 2;
for(M = i-1; M > -1; M--, ch--){
display_buffer[ch] = B[M];
}
}
/**
* convert integer value i into string and display it
* @param i - value to display, -99 <= i <= 999, if wrong, displays "---E"
*/
void display_int(int I, char voltmeter){
int rem;
U8 pos = 0; //DP position
char N = 2, sign = 0, i;
if(I < -99 || I > 999){
set_display_buf("--E");
return;
}
// prepare buffer for voltmeter's values
if(voltmeter){
for(i = 0; i < 3; i++)
display_buffer[i] = 0;
if(I>999){
I /= 10;
pos = 1; // DP is in 2nd position - voltage more than 9.99V
}
}else{
for(i = 0; i < 3; i++)
display_buffer[i] = ' ';
}
if(I == 0){ // just show zero
display_buffer[2] = 0;
return;
}
if(I < 0){
sign = 1;
I *= -1;
}
do{
rem = I % 10;
display_buffer[N] = rem;
I /= 10;
}while(--N > -1 && I);
if(sign && N > -1) display_buffer[N] = 16; // minus sign
if(voltmeter) display_buffer[pos] |= 0x80;
}
/**
* displays digital point at position i
* @param i - position to display DP, concequent calls can light up many DPs
*/
void display_DP_at_pos(U8 i){
if(i > 2) return;
display_buffer[i] |= 0x80;
}

View File

@@ -0,0 +1,35 @@
/*
* led.h
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __LED_H__
#define __LED_H__
#include "stm8l.h"
extern volatile U8 buttons_state; // flags for button: 1 - pressed, 0 - not pressed
void LED_init();
void set_display_buf(char *str);
void show_next_digit();
void display_int(int i, char voltmeter);
void display_DP_at_pos(U8 i);
#endif // __LED_H__

View File

@@ -0,0 +1,132 @@
/*
* main.c
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "main.h"
#include "interrupts.h"
#include "led.h"
/*
int temp;
#define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); }
#define PIX_SWAP(a,b) { temp=(a);(a)=(b);(b)=temp; }
int p[9]; // buffer for median filtering
int opt_med9(){
PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
PIX_SORT(p[0], p[1]) ; PIX_SORT(p[3], p[4]) ; PIX_SORT(p[6], p[7]) ;
PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
PIX_SORT(p[0], p[3]) ; PIX_SORT(p[5], p[8]) ; PIX_SORT(p[4], p[7]) ;
PIX_SORT(p[3], p[6]) ; PIX_SORT(p[1], p[4]) ; PIX_SORT(p[2], p[5]) ;
PIX_SORT(p[4], p[7]) ; PIX_SORT(p[4], p[2]) ; PIX_SORT(p[6], p[4]) ;
PIX_SORT(p[4], p[2]) ; return(p[4]) ;
}
*/
U32 Global_time = 0L; // global time in ms
// one digit emitting time
#define LED_delay 1
// pause between buttons actions
#define BTNS_delay 30
int main() {
U32 T_LED = 0L; // time of last digit update
U32 T_time = 0L; // timer
U32 T_btns = 0L; // buttons timer
U8 old_btns_state = 0;
//U8 tmpva = 0;
// int pidx = 0; // index in median buffer
// long cntrin = 0, cntrcap = 0; // counters for average
// Configure clocking
CLK_CKDIVR = 0; // F_HSI = 16MHz, f_CPU = 16MHz
// Configure pins
CFG_GCR |= 1; // disable SWIM
LED_init();
CCR |= 0x28; // make shure that we are on level 3 - disabled SW priority
// Configure Timer1
// prescaler = f_{in}/f_{tim1} - 1
// set Timer1 to 1MHz: 16/1 - 1 = 15
TIM1_PSCRH = 0;
TIM1_PSCRL = 15; // LSB should be written last as it updates prescaler
// auto-reload each 1ms: TIM_ARR = 1000 = 0x03E8
TIM1_ARRH = 0x03;
TIM1_ARRL = 0xE8;
// interrupts: update
TIM1_IER = TIM_IER_UIE;
// auto-reload + interrupt on overflow + enable
TIM1_CR1 = TIM_CR1_APRE | TIM_CR1_URS | TIM_CR1_CEN;
// enable all interrupts
enableInterrupts();
set_display_buf("abc");
// Loop
do {
// onse per 300ms refresh displayed value
if(((unsigned int)(Global_time - T_time) > 300) || (T_time > Global_time)){
T_time = Global_time;
// display_int((int)tmpva++,0);
// cntrin = 0;cntrcap = 0;voltagein = 0L;voltagecap = 0L;pidx = 0;
}
if((U8)(Global_time - T_LED) > LED_delay){
T_LED = Global_time;
show_next_digit();
}
if((U8)(Global_time - T_btns) > BTNS_delay){
T_btns = Global_time;
if(old_btns_state != buttons_state){
U8 pressed = old_btns_state & ~buttons_state; // pressed buttons are ones
if(pressed){ // display
//display_int(pressed, 0);
display_int(buttons_state, 0);
}else{ // some buttons released
if(buttons_state == 0xff){ // all buttons released
set_display_buf("abc");
}else{
display_int(~old_btns_state & buttons_state, 0); // released are ones
}
}
old_btns_state = buttons_state;
}
}
} while(1);
}
/*
if(ADC_ready){
// prepare data for rounded output
p[pidx] = ADC_value;
if(++pidx == 9){ // buffer is ready
if(vcap){
voltagecap += (long)(opt_med9());
cntrcap++;
ADC_CSR = 0x24; // switch to ain
vcap = 0;
}else{
voltagein += (long)(opt_med9());
cntrin++;
ADC_CSR = 0x26; // switch to vcap
vcap = 1;
}
pidx = 0;
}
ADC_ready = 0;
}
*/

View File

@@ -0,0 +1,30 @@
/*
* main.h
*
* Copyright 2015 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __MAIN_H__
#define __MAIN_H__
#include "stm8l.h"
#define CONCAT(a,b) a##_##b
#define PORT(a,b) CONCAT(a,b)
#endif // __MAIN_H__

View File

@@ -0,0 +1,58 @@
:2080A000808080808080808080AE5255F644241B90CE000472A90001C60003A90097C60025
:1980C00002A9009590CF0004CF0002AE52557F808080808080808080805F
:208000008200808382000000820080A0820080A1820080A2820080A3820080A4820080A57E
:20802000820080A6820080A78200000082000000820080A8820080A9820080D0820080D1F1
:20804000820080D28200000082000000820080D3820080D4820080D58200000082000000C2
:20806000820080D6820080D7820080D88200000082000000820000008200000082000000EB
:1D808300AE00012707724F00005A26F9AE003E2709D6866ED700015A26F7CC8080C8
:03808000CC80D9D8
:2080D900521D5F1F0C1F0A5F1F081F065F1F041F020F01AE50C67FAE7F60F6AA01F7CD8250
:2080F90008AE7F0AF6AA28F7AE52607FAE5261A60FF7AE5262A603F7AE5263A6E8F7AE5293
:2081190054A601F7AE5250A685F79AAE82041F0E1E0E89CD83A45B02CE000472F008C600DF
:208139000312076B1BC600021206C600056B1390CE0003C600026B10A3012C2211CE0004E2
:208159001308C600031207C600021206240A17077B136B097B106B06C60005887B0E6B1A7E
:20817900841019A101230D170B7B136B0D7B106B0ACD823AC60005887B066B17841016A115
:208199001E2395CE00041F04CE00021F027B01C100012603CC8131C600014314014D271082
:2081B900C60001974F954B0089CD84D55B032030C60001A1FF260A1E0E89CD83A45B0220FF
:2081D9001F7B016B180F171E1753C600010F1489140285979E1414954B0089CD84D55B0362
:0F81F900C600016B01CC81315B1D8161626300A7
:04866F000000000007
:20820800AE5002F6AA08F7AE5011F6AA30F7AE5003F6AA08F7AE5012F6AA30F7AE5005F671
:20822800A4CFF7AE500AF6A407F7AE500FF6A4FDF7815206AE00069FCB0009979EA900951E
:20824800F6A47F6B01AE500FF6A4CFF7AE5000F6A4F7F7AE5007F6A4CFF7AE500CF6A4078E
:20826800F7AE5011F6A4FDF7AE5008F6AA30F7AE500DF6AAF8F7AE5012F6AA02F7C6000983
:20828800A1012621AE5006F6A4304EA40F6B03AE5010F6A402481A036B04AE500BF6A4F897
:2082A8001A04C70001AE5002F6A4F7F7AE5003F6A4F7F7AE5011F6A4CFF7AE5012F6A4CFD7
:2082C800F7AE5008F6A4CFF7AE500DF6A407F7AE5012F6A4FDF77B01A1122448AE5007F662
:2082E8006B06AE000A9F1B01979EA90095F61A06AE5007F7AE500CF66B05AE001C9F1B0118
:20830800979EA90095F61A05AE500CF7AE5011F66B02AE002E9F1B01979EA90095F61A023E
:20832800AE5011F77B01482407AE500CF6AA40F7C60009A1002710C60009A1012720C6003A
:2083480009A10227302043AE5002F6AA08F7AE5003F6AA08F7AE5000F6AA08F7202CAE5089
:2083680011F6AA10F7AE5012F6AA10F7AE500FF6AA10F72015AE5011F6AA20F7AE5012F6D1
:20838800AA20F7AE500FF6AA20F7C600094CC70009A1022304725F00095B06815212725FAA
:2083A8000009AE00061F114F5F9772FB1188A620F7844CA1032FF11E152603CC84D2965CBC
:2083C8001F0F0F041615170D1E0DF66B06887B054A6B0D844D2603CC84A67B04A1032F0364
:2083E800CC84A64F957B06A12F2D0C7B06A13A2E06A63095CC848B7B06A1602C040F0B204F
:2084080004A6016B0B7B06A1672F034F2002A601140B4D2706A65795CC848B7B06A1402CCC
:20842800040F0A2004A6016B0A7B06A1472F034F2002A601140A4D2705A6379520457B0635
:20844800A12D2605A61D95203A7B06A1682605A65795202F7B06A1482605A6379520247B0D
:2084680006A12E26180D0426071E0FA6FFF720265F7B0C9772FB0FF6AA80F720197B06A129
:20848800202613905F7B04909772F90F7B068910018590F70C041E0D5C1F0DCC83D07B0CDC
:2084A8006B057B056B09A6026B067B09A1FF2D1A5F7B069772FB111F075F7B099772FB0FBB
:2084C800F61E07F70A090A0620E05B1281520A0F030F011E0DA3FF9D2F131E0DA303E72C63
:2084E800040F0A2004A6016B0A0D0A270CAE85D889CD83A45B02CC85C00D0F2729AE0006B7
:208508001F044F5F9772FB047F4CA1032FF50D0A27294B0A4B001E0F89CD861A5B041F0D32
:20852800A6016B032015AE00061F064F5F9772FB0688A620F7844CA1032FF11E0D2607AE79
:2085480000087FCC85C01E0DA300002E09A6016B011E0D501F0DAE00061F08A6026B024B81
:208568000A4B001E0F89CD85DC5B04905F7B02909772F9089F90F74B0A4B001E0F89CD8686
:208588001A5B041F0D0A027B02A1FF2C034F2002A6014D27041E0D26C60D01270D4D270A6F
:2085A8005F7B029772FB08A610F70D0F270A5F7B039772FB087999765B0A817B03A1022237
:1485C8000EAE00069F1B03979EA90095799976812D2D450005
:20867300202020003020202030101020303030101020101000103800B8A880A8B808B8A8A7
:1A86930098B038B0B898809002020002020202020202020200020000000223
:2085DC0052051E08A300002F040F012004A6016B010D0127051E085020021E081F041E0AA2
:2085FC00A300002E071E0A501F022004160A170216021E0465930D012701505B058152089E
:20861C001E0BA300002F040F052004A6016B050D0527051E0B5020021E0B1F011E0DA30000
:20863C00002F040F062004A6016B060D0627107B0E406B044F120D6B0316031707200416CB
:13865C000D170716071E01657B0518064D2701505B0881F8
:00000001FF

View File

@@ -0,0 +1,89 @@
update=Пт 10 апр 2015 00:07:11
version=1
last_client=kicad
[cvpcb]
version=1
NetIExt=net
[cvpcb/libraries]
EquName1=devcms
[pcbnew]
version=1
LastNetListRead=
PadDrlX=320
PadDimH=550
PadDimV=550
BoardThickness=620
TxtPcbV=600
TxtPcbH=600
TxtModV=500
TxtModH=500
TxtModW=100
VEgarde=100
DrawLar=120
EdgeLar=80
TxtLar=120
MSegLar=120
[pcbnew/libraries]
LibDir=
LibName1=sockets
LibName2=connect
LibName3=discret
LibName4=pin_array
LibName5=divers
LibName6=libcms
LibName7=display
LibName8=led
LibName9=dip_sockets
LibName10=pga_sockets
LibName11=valves
[general]
version=1
[eeschema]
version=1
PageLayoutDescrFile=
SubpartIdSeparator=0
SubpartFirstId=65
LibDir=/home/eddy/Docs/ELECTRONICS/STM8/voltmeters/kicad
NetFmtName=
SpiceForceRefPrefix=0
SpiceUseNetNumbers=0
RptD_X=0
RptD_Y=100
RptLab=1
LabSize=60
[eeschema/libraries]
LibName1=power
LibName2=device
LibName3=transistors
LibName4=conn
LibName5=linear
LibName6=regul
LibName7=74xx
LibName8=cmos4000
LibName9=adc-dac
LibName10=memory
LibName11=xilinx
LibName12=special
LibName13=microcontrollers
LibName14=dsp
LibName15=microchip
LibName16=analog_switches
LibName17=motorola
LibName18=texas
LibName19=intel
LibName20=audio
LibName21=interface
LibName22=digital-audio
LibName23=philips
LibName24=display
LibName25=cypress
LibName26=siliconi
LibName27=opto
LibName28=atmel
LibName29=contrib
LibName30=valves
LibName31=stm8
LibName32=ht7136
LibName33=mcp3421
LibName34=seven_segm
LibName35=stm8s003

View File

@@ -0,0 +1,625 @@
EESchema Schematic File Version 2
LIBS:power
LIBS:device
LIBS:transistors
LIBS:conn
LIBS:linear
LIBS:regul
LIBS:74xx
LIBS:cmos4000
LIBS:adc-dac
LIBS:memory
LIBS:xilinx
LIBS:special
LIBS:microcontrollers
LIBS:dsp
LIBS:microchip
LIBS:analog_switches
LIBS:motorola
LIBS:texas
LIBS:intel
LIBS:audio
LIBS:interface
LIBS:digital-audio
LIBS:philips
LIBS:display
LIBS:cypress
LIBS:siliconi
LIBS:opto
LIBS:atmel
LIBS:contrib
LIBS:valves
LIBS:stm8
LIBS:3digit_voltmeter-cache
EELAYER 24 0
EELAYER END
$Descr A4 11693 8268
encoding utf-8
Sheet 1 1
Title ""
Date "16 feb 2015"
Rev ""
Comp ""
Comment1 ""
Comment2 ""
Comment3 ""
Comment4 ""
$EndDescr
$Comp
L STM8S003F3P6 IC1
U 1 1 54CCE7DB
P 5050 4600
F 0 "IC1" H 5050 5200 60 0000 C CNN
F 1 "STM8S003F3P6" H 5050 3800 60 0000 C CNN
F 2 "TSSOP20" H 4950 5100 60 0001 C CNN
F 3 "~" H 5050 4600 60 0000 C CNN
1 5050 4600
1 0 0 -1
$EndComp
$Comp
L R_PACK4 RP2
U 1 1 54CCE809
P 7200 4200
F 0 "RP2" H 7200 4650 40 0000 C CNN
F 1 "220" H 7200 4150 40 0000 C CNN
F 2 "" H 7200 4200 60 0000 C CNN
F 3 "" H 7200 4200 60 0000 C CNN
1 7200 4200
1 0 0 1
$EndComp
$Comp
L ARK-SP410361N DIS2
U 1 1 54CCF1F0
P 6550 3100
F 0 "DIS2" H 6550 3600 60 0000 C CNN
F 1 "ARK-SP410361N" H 6550 2650 60 0000 C CNN
F 2 "~" H 6300 3100 60 0000 C CNN
F 3 "~" H 6300 3100 60 0000 C CNN
1 6550 3100
1 0 0 -1
$EndComp
$Comp
L HT7136 U2
U 1 1 54CD13ED
P 3200 3050
F 0 "U2" H 3350 2854 60 0000 C CNN
F 1 "HT7136" H 3200 3250 60 0000 C CNN
F 2 "~" H 3200 3050 60 0000 C CNN
F 3 "~" H 3200 3050 60 0000 C CNN
1 3200 3050
1 0 0 -1
$EndComp
$Comp
L GND #PWR01
U 1 1 54CD1463
P 3200 3400
F 0 "#PWR01" H 3200 3400 30 0001 C CNN
F 1 "GND" H 3200 3330 30 0001 C CNN
F 2 "" H 3200 3400 60 0000 C CNN
F 3 "" H 3200 3400 60 0000 C CNN
1 3200 3400
1 0 0 -1
$EndComp
Wire Wire Line
3200 3400 3200 3300
$Comp
L C C1
U 1 1 54CD1475
P 2700 3350
F 0 "C1" H 2750 3450 50 0000 L CNN
F 1 "100n" H 2750 3250 50 0000 L CNN
F 2 "" H 2700 3350 60 0000 C CNN
F 3 "" H 2700 3350 60 0000 C CNN
1 2700 3350
1 0 0 -1
$EndComp
Wire Wire Line
2700 3150 2700 3000
$Comp
L GND #PWR02
U 1 1 54CD148D
P 2700 3650
F 0 "#PWR02" H 2700 3650 30 0001 C CNN
F 1 "GND" H 2700 3580 30 0001 C CNN
F 2 "" H 2700 3650 60 0000 C CNN
F 3 "" H 2700 3650 60 0000 C CNN
1 2700 3650
1 0 0 -1
$EndComp
Wire Wire Line
2700 3550 2700 3650
$Comp
L CP1 C2
U 1 1 54CD14C2
P 3750 3200
F 0 "C2" H 3800 3300 50 0000 L CNN
F 1 "100u" H 3800 3100 50 0000 L CNN
F 2 "" H 3750 3200 60 0000 C CNN
F 3 "" H 3750 3200 60 0000 C CNN
1 3750 3200
1 0 0 -1
$EndComp
Wire Wire Line
3600 3000 3900 3000
$Comp
L GND #PWR03
U 1 1 54CD271D
P 3750 3500
F 0 "#PWR03" H 3750 3500 30 0001 C CNN
F 1 "GND" H 3750 3430 30 0001 C CNN
F 2 "" H 3750 3500 60 0000 C CNN
F 3 "" H 3750 3500 60 0000 C CNN
1 3750 3500
1 0 0 -1
$EndComp
Wire Wire Line
3750 3400 3750 3500
Connection ~ 3750 3000
$Comp
L VCC #PWR04
U 1 1 54CD31C2
P 3900 3000
F 0 "#PWR04" H 3900 3100 30 0001 C CNN
F 1 "VCC" H 3900 3100 30 0000 C CNN
F 2 "" H 3900 3000 60 0000 C CNN
F 3 "" H 3900 3000 60 0000 C CNN
1 3900 3000
1 0 0 -1
$EndComp
$Comp
L CONN_4 P1
U 1 1 54CD436B
P 4900 2950
F 0 "P1" V 4850 2950 50 0000 C CNN
F 1 "CONN_5" V 4950 2950 50 0000 C CNN
F 2 "" H 4900 2950 60 0000 C CNN
F 3 "" H 4900 2950 60 0000 C CNN
1 4900 2950
0 1 -1 0
$EndComp
Wire Wire Line
5050 3450 5050 3300
$Comp
L R_PACK4 RP1
U 1 1 54CD4EA1
P 6950 4800
F 0 "RP1" H 6950 5250 40 0000 C CNN
F 1 "220" H 6950 4750 40 0000 C CNN
F 2 "" H 6950 4800 60 0000 C CNN
F 3 "" H 6950 4800 60 0000 C CNN
1 6950 4800
1 0 0 1
$EndComp
Text Label 7400 4350 0 60 ~ 0
G
Text Label 7400 4450 0 60 ~ 0
DP
Text Label 7150 4950 0 60 ~ 0
A
Text Label 7150 5050 0 60 ~ 0
F
Text Label 7400 4550 0 60 ~ 0
D
Text Label 7150 4850 0 60 ~ 0
E
Text Label 7400 4250 0 60 ~ 0
C
Text Label 7150 5150 0 60 ~ 0
B
Text Label 5450 3250 2 60 ~ 0
G
Text Label 5450 3050 2 60 ~ 0
DP
Text Label 7600 2950 0 60 ~ 0
A
Text Label 7600 3050 0 60 ~ 0
F
Text Label 5450 2950 2 60 ~ 0
D
Text Label 5450 2850 2 60 ~ 0
E
Text Label 5450 3150 2 60 ~ 0
C
Text Label 7600 3350 0 60 ~ 0
B
Text Label 4850 3300 3 60 ~ 0
SWIM
Text Label 4750 3300 3 60 ~ 0
RST
Text Label 7600 2850 0 60 ~ 0
A1
Text Label 7600 3150 0 60 ~ 0
A2
Text Label 7600 3250 0 60 ~ 0
A3
$Comp
L VCC #PWR05
U 1 1 54CD9F1D
P 3750 5050
F 0 "#PWR05" H 3750 5150 30 0001 C CNN
F 1 "VCC" H 3750 5150 30 0000 C CNN
F 2 "" H 3750 5050 60 0000 C CNN
F 3 "" H 3750 5050 60 0000 C CNN
1 3750 5050
0 -1 -1 0
$EndComp
$Comp
L GND #PWR06
U 1 1 54CDA116
P 3700 4850
F 0 "#PWR06" H 3700 4850 30 0001 C CNN
F 1 "GND" H 3700 4780 30 0001 C CNN
F 2 "" H 3700 4850 60 0000 C CNN
F 3 "" H 3700 4850 60 0000 C CNN
1 3700 4850
0 1 1 0
$EndComp
$Comp
L C C3
U 1 1 54CDA380
P 3600 5450
F 0 "C3" H 3600 5550 40 0000 L CNN
F 1 "0.68u" H 3606 5365 40 0000 L CNN
F 2 "" H 3638 5300 30 0000 C CNN
F 3 "" H 3600 5450 60 0000 C CNN
1 3600 5450
1 0 0 -1
$EndComp
Wire Wire Line
3600 4450 3600 5250
Wire Wire Line
3600 4950 3800 4950
$Comp
L GND #PWR07
U 1 1 54CDA4A6
P 3600 5750
F 0 "#PWR07" H 3600 5750 30 0001 C CNN
F 1 "GND" H 3600 5680 30 0001 C CNN
F 2 "" H 3600 5750 60 0000 C CNN
F 3 "" H 3600 5750 60 0000 C CNN
1 3600 5750
1 0 0 -1
$EndComp
Wire Wire Line
3600 5750 3600 5650
Text Label 3800 4350 2 60 ~ 0
A3
Text Label 3800 4250 2 60 ~ 0
A2
Wire Wire Line
3600 4450 3800 4450
Connection ~ 3600 4950
Wire Wire Line
3700 4850 3800 4850
Wire Wire Line
3750 5050 3800 5050
Wire Wire Line
2700 3000 2800 3000
Text Label 3800 4550 2 60 ~ 0
RST
Text Label 6400 4450 0 60 ~ 0
SWIM
Text Label 3800 5150 2 60 ~ 0
A1
Wire Wire Line
6400 5150 6750 5150
Wire Wire Line
6400 5050 6750 5050
Wire Wire Line
6400 4950 6750 4950
Wire Wire Line
6400 4850 6750 4850
$Comp
L CONN_2 P2
U 1 1 54E2B17F
P 1400 2950
F 0 "P2" V 1350 2950 40 0000 C CNN
F 1 "CONN_2" V 1450 2950 40 0000 C CNN
F 2 "" H 1400 2950 60 0000 C CNN
F 3 "" H 1400 2950 60 0000 C CNN
1 1400 2950
-1 0 0 1
$EndComp
$Comp
L GND #PWR08
U 1 1 54E2B1F6
P 1750 3200
F 0 "#PWR08" H 1750 3200 30 0001 C CNN
F 1 "GND" H 1750 3130 30 0001 C CNN
F 2 "" H 1750 3200 60 0000 C CNN
F 3 "" H 1750 3200 60 0000 C CNN
1 1750 3200
1 0 0 -1
$EndComp
Wire Wire Line
1750 3050 1750 3200
Text Label 1750 2850 0 60 ~ 0
VIN
Text Label 2700 3000 2 60 ~ 0
VIN
Text Label 4950 3300 3 60 ~ 0
VIN
$Comp
L GND #PWR09
U 1 1 54CD4689
P 5050 3450
F 0 "#PWR09" H 5050 3450 30 0001 C CNN
F 1 "GND" H 5050 3380 30 0001 C CNN
F 2 "" H 5050 3450 60 0000 C CNN
F 3 "" H 5050 3450 60 0000 C CNN
1 5050 3450
1 0 0 -1
$EndComp
$Comp
L R R3
U 1 1 54E2B6E2
P 2550 4450
F 0 "R3" V 2630 4450 40 0000 C CNN
F 1 "absent" V 2557 4451 40 0000 C CNN
F 2 "" V 2480 4450 30 0000 C CNN
F 3 "" H 2550 4450 30 0000 C CNN
1 2550 4450
1 0 0 -1
$EndComp
$Comp
L VCC #PWR010
U 1 1 54E2B7D6
P 2550 4100
F 0 "#PWR010" H 2550 4200 30 0001 C CNN
F 1 "VCC" H 2550 4200 30 0000 C CNN
F 2 "" H 2550 4100 60 0000 C CNN
F 3 "" H 2550 4100 60 0000 C CNN
1 2550 4100
1 0 0 -1
$EndComp
Wire Wire Line
2550 4100 2550 4200
$Comp
L R R2
U 1 1 54E2B804
P 2550 5050
F 0 "R2" V 2630 5050 40 0000 C CNN
F 1 "10k" V 2557 5051 40 0000 C CNN
F 2 "" V 2480 5050 30 0000 C CNN
F 3 "" H 2550 5050 30 0000 C CNN
1 2550 5050
1 0 0 -1
$EndComp
Wire Wire Line
2550 4800 2550 4700
$Comp
L C C4
U 1 1 54E2BAD0
P 2850 5100
F 0 "C4" H 2850 5200 40 0000 L CNN
F 1 "absent" H 2856 5015 40 0000 L CNN
F 2 "" H 2888 4950 30 0000 C CNN
F 3 "" H 2850 5100 60 0000 C CNN
1 2850 5100
1 0 0 -1
$EndComp
Text Label 6400 4250 0 60 ~ 0
AIN
Text Label 3000 4750 0 60 ~ 0
AIN
Connection ~ 2550 4750
Wire Wire Line
2550 5300 2850 5300
Wire Wire Line
2850 4900 2850 4750
Connection ~ 2850 4750
Wire Wire Line
2150 4750 3000 4750
Wire Wire Line
6400 4750 6850 4750
Wire Wire Line
6400 4650 6800 4650
Wire Wire Line
6400 4550 6750 4550
Wire Wire Line
6850 4750 6850 4550
Wire Wire Line
6850 4550 7000 4550
Wire Wire Line
6800 4650 6800 4450
Wire Wire Line
6800 4450 7000 4450
Wire Wire Line
6750 4550 6750 4350
Wire Wire Line
6750 4350 7000 4350
Wire Wire Line
6400 4450 6650 4450
Wire Wire Line
6650 4450 6650 4250
Wire Wire Line
6650 4250 7000 4250
$Comp
L R R1
U 1 1 54E2D592
P 2150 4400
F 0 "R1" V 2230 4400 40 0000 C CNN
F 1 "91k" V 2157 4401 40 0000 C CNN
F 2 "" V 2080 4400 30 0000 C CNN
F 3 "" H 2150 4400 30 0000 C CNN
1 2150 4400
1 0 0 -1
$EndComp
Wire Wire Line
2150 4750 2150 4650
Text Label 2150 4150 2 60 ~ 0
VIN
NoConn ~ 3800 4650
NoConn ~ 3800 4750
NoConn ~ 6400 4350
$Comp
L GND #PWR?
U 1 1 54E2711D
P 2700 5400
F 0 "#PWR?" H 2700 5400 30 0001 C CNN
F 1 "GND" H 2700 5330 30 0001 C CNN
F 2 "" H 2700 5400 60 0000 C CNN
F 3 "" H 2700 5400 60 0000 C CNN
1 2700 5400
1 0 0 -1
$EndComp
Wire Wire Line
2700 5400 2700 5300
Connection ~ 2700 5300
Text Notes 900 5000 0 60 ~ 0
Remove R2 & C4\nSolder R3: 4.7k\nInstead o9f R1 solder jumper
$Comp
L DS18x20 DD1
U 1 1 5526FD33
P 1050 2050
F 0 "DD1" H 1050 2500 60 0000 C CNN
F 1 "DS18x20" H 1050 2400 60 0000 C CNN
F 2 "" H 1050 2050 60 0000 C CNN
F 3 "" H 1050 2050 60 0000 C CNN
1 1050 2050
1 0 0 -1
$EndComp
Wire Wire Line
1750 2850 1750 2550
Wire Wire Line
1750 2550 1050 2550
Wire Wire Line
1050 2550 1050 2350
Wire Wire Line
1750 3150 950 3150
Wire Wire Line
950 3150 950 2350
Connection ~ 1750 3150
Wire Wire Line
1150 2350 2050 2350
$Comp
L VCC #PWR?
U 1 1 552709AA
P 2050 2350
F 0 "#PWR?" H 2050 2450 30 0001 C CNN
F 1 "VCC" H 2050 2450 30 0000 C CNN
F 2 "" H 2050 2350 60 0000 C CNN
F 3 "" H 2050 2350 60 0000 C CNN
1 2050 2350
1 0 0 -1
$EndComp
Text Notes 1600 2200 0 60 ~ 0
Solder this wire to Vcc
Text Notes 8100 4850 0 60 ~ 0
To attach keys solder wires to them directly to LED legs\nCapacitor (10nF) and resisror (47..56kOhm) solder on key
$Comp
L SW_PUSH SWN
U 1 1 552713A2
P 8400 5150
F 0 "SWN" H 8550 5260 50 0000 C CNN
F 1 "SW_PUSH" H 8400 5070 50 0000 C CNN
F 2 "" H 8400 5150 60 0000 C CNN
F 3 "" H 8400 5150 60 0000 C CNN
1 8400 5150
1 0 0 -1
$EndComp
Wire Wire Line
7150 5150 8100 5150
$Comp
L C CN
U 1 1 5527146F
P 9000 5150
F 0 "CN" H 9000 5250 40 0000 L CNN
F 1 "10n" H 9006 5065 40 0000 L CNN
F 2 "" H 9038 5000 30 0000 C CNN
F 3 "" H 9000 5150 60 0000 C CNN
1 9000 5150
0 1 1 0
$EndComp
$Comp
L R RN
U 1 1 55271518
P 8750 5400
F 0 "RN" V 8830 5400 40 0000 C CNN
F 1 "56k" V 8757 5401 40 0000 C CNN
F 2 "" V 8680 5400 30 0000 C CNN
F 3 "" H 8750 5400 30 0000 C CNN
1 8750 5400
0 1 1 0
$EndComp
Wire Wire Line
8000 5150 8000 5400
Wire Wire Line
8000 5400 8500 5400
Connection ~ 8000 5150
Wire Wire Line
8700 5150 8800 5150
$Comp
L GND #PWR?
U 1 1 552716D4
P 9450 5300
F 0 "#PWR?" H 9450 5300 30 0001 C CNN
F 1 "GND" H 9450 5230 30 0001 C CNN
F 2 "" H 9450 5300 60 0000 C CNN
F 3 "" H 9450 5300 60 0000 C CNN
1 9450 5300
1 0 0 -1
$EndComp
Wire Wire Line
9450 5300 9450 5150
Wire Wire Line
9450 5150 9200 5150
Wire Wire Line
9000 5400 9300 5400
Wire Wire Line
9300 5400 9300 5150
Connection ~ 9300 5150
$Comp
L SW_PUSH SWX
U 1 1 55283145
P 8350 3700
F 0 "SWX" H 8500 3810 50 0000 C CNN
F 1 "SW_PUSH" H 8350 3620 50 0000 C CNN
F 2 "" H 8350 3700 60 0000 C CNN
F 3 "" H 8350 3700 60 0000 C CNN
1 8350 3700
1 0 0 -1
$EndComp
$Comp
L DIODE D1
U 1 1 5528332E
P 9000 3700
F 0 "D1" H 9000 3800 40 0000 C CNN
F 1 "DIODE" H 9000 3600 40 0000 C CNN
F 2 "" H 9000 3700 60 0000 C CNN
F 3 "" H 9000 3700 60 0000 C CNN
1 9000 3700
1 0 0 -1
$EndComp
Wire Wire Line
9300 3700 9200 3700
Wire Wire Line
8650 3700 8800 3700
Text Label 9300 3700 0 60 ~ 0
A1
Wire Wire Line
7700 5150 7700 3700
Wire Wire Line
7700 3700 8050 3700
Connection ~ 7700 5150
Text Notes 8150 3450 0 60 ~ 0
Another variant of button's attaching:\nafter power off current digit we setup all segments pins\nas pullup inputs and turn current ditit's pin into 0\nif button pressed we get 0 at appropriate pin else we have 1\n\n!!! When digit is off set anode pin into input mode !!!
Wire Notes Line
8000 2800 8000 3900
Wire Notes Line
8000 3900 11050 3900
Wire Notes Line
11050 3900 11050 2800
Wire Notes Line
11050 2800 8000 2800
Wire Notes Line
7900 4500 7900 5550
Wire Notes Line
10850 4500 7900 4500
Wire Notes Line
10850 5550 10850 4500
Wire Notes Line
7900 5550 10850 5550
Text Notes 9300 3850 0 39 ~ 0
This variant lets us to connect 8 buttons to each digit!
$EndSCHEMATC

View File

@@ -0,0 +1,33 @@
NAME=testproj
SDCC=sdcc
CCFLAGS=-DSTM8S003 -I../ -I../../ -I/usr/share/sdcc/include -mstm8 --out-fmt-ihx -DBUTNS
LDFLAGS=-mstm8 --out-fmt-ihx -lstm8
FLASHFLAGS=-cstlinkv2 -pstm8s003
SRC=$(wildcard *.c)
OBJ=$(SRC:%.c=%.rel)
TRASH=$(OBJ) $(SRC:%.c=%.rst) $(SRC:%.c=%.asm) $(SRC:%.c=%.lst)
TRASH+=$(SRC:%.c=%.sym) $(NAME).lk $(NAME).map
INDEPENDENT_HEADERS=../stm8l.h Makefile
all: $(NAME).ihx
$(SRC) : %.c : %.h $(INDEPENDENT_HEADERS)
@touch $@
%.h: ;
clean:
rm -f $(TRASH)
load: $(NAME).ihx
stm8flash $(FLASHFLAGS) -w $(NAME).ihx
%.rel: %.c
$(SDCC) $(CCFLAGS) -c $<
$(NAME).ihx: $(OBJ)
$(SDCC) $(LDFLAGS) $(OBJ) -o $(NAME).ihx
.PHONY: all

View File

@@ -0,0 +1,149 @@
/*
* interrupts.c
*
* Copyright 2015 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "stm8l.h"
#include "interrupts.h"
// Top Level Interrupt
INTERRUPT_HANDLER(TLI_IRQHandler, 0){}
// Auto Wake Up Interrupt
INTERRUPT_HANDLER(AWU_IRQHandler, 1){}
// Clock Controller Interrupt
INTERRUPT_HANDLER(CLK_IRQHandler, 2){}
// External Interrupt PORTA
INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3){}
// External Interrupt PORTB
INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4){}
// External Interrupt PORTC
INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5){}
// External Interrupt PORTD
INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6){}
// External Interrupt PORTE
INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7){}
#ifdef STM8S903
// External Interrupt PORTF
INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler, 8){}
#endif // STM8S903
#if defined (STM8S208) || defined (STM8AF52Ax)
// CAN RX Interrupt routine.
INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8){}
// CAN TX Interrupt routine.
INTERRUPT_HANDLER(CAN_TX_IRQHandler, 9){}
#endif // STM8S208 || STM8AF52Ax
// SPI Interrupt routine.
INTERRUPT_HANDLER(SPI_IRQHandler, 10){}
// Timer1 Update/Overflow/Trigger/Break Interrupt
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11){
if(TIM1_SR1 & TIM_SR1_UIF){ // update interrupt
Global_time++; // increase timer
}
TIM1_SR1 = 0; // clear all interrupt flags
}
// Timer1 Capture/Compare Interrupt routine.
INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12){}
#ifdef STM8S903
// Timer5 Update/Overflow/Break/Trigger Interrupt
INTERRUPT_HANDLER(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13){}
// Timer5 Capture/Compare Interrupt
INTERRUPT_HANDLER(TIM5_CAP_COM_IRQHandler, 14){}
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
// Timer2 Update/Overflow/Break Interrupt
INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13){}
// Timer2 Capture/Compare Interrupt
// process soft I2C
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14){
}
#endif // STM8S903
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \
defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x)
// Timer3 Update/Overflow/Break Interrupt
INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15){}
// Timer3 Capture/Compare Interrupt
INTERRUPT_HANDLER(TIM3_CAP_COM_IRQHandler, 16){}
#endif // STM8S208, STM8S207 or STM8S105 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \
defined(STM8S003) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903)
// UART1 TX Interrupt
INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17){}
// UART1 RX Interrupt
INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18){}
#endif // STM8S208 or STM8S207 or STM8S103 or STM8S903 or STM8AF62Ax or STM8AF52Ax
// I2C Interrupt
INTERRUPT_HANDLER(I2C_IRQHandler, 19){}
#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x)
// UART2 TX interrupt
INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20){}
// UART2 RX interrupt
INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21){}
#endif // STM8S105 or STM8AF626x
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// UART3 TX interrupt
INTERRUPT_HANDLER(UART3_TX_IRQHandler, 20){}
// UART3 RX interrupt
INTERRUPT_HANDLER(UART3_RX_IRQHandler, 21){}
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// ADC2 interrupt
INTERRUPT_HANDLER(ADC2_IRQHandler, 22){}
#else
// ADC1 interrupt
INTERRUPT_HANDLER(ADC1_IRQHandler, 22){
}
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#ifdef STM8S903
// Timer6 Update/Overflow/Trigger Interrupt
INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23){}
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF52Ax or STM8AF62Ax or STM8AF626x
// Timer4 Update/Overflow Interrupt
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23){}
#endif // STM8S903
// Eeprom EEC Interrupt
INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24){}

View File

@@ -0,0 +1,148 @@
/*
* interrupts.h
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __INTERRUPTS_H__
#define __INTERRUPTS_H__
#include "stm8l.h"
extern U8 ADC_ready; // flag: data ready
extern U32 Global_time; // global time in ms
extern int ADC_value; // value of last ADC measurement
// Top Level Interrupt
INTERRUPT_DEFINITION(TLI_IRQHandler, 0);
// Auto Wake Up Interrupt
INTERRUPT_DEFINITION(AWU_IRQHandler, 1);
// Clock Controller Interrupt
INTERRUPT_DEFINITION(CLK_IRQHandler, 2);
// External Interrupt PORTA
INTERRUPT_DEFINITION(EXTI_PORTA_IRQHandler, 3);
// External Interrupt PORTB
INTERRUPT_DEFINITION(EXTI_PORTB_IRQHandler, 4);
// External Interrupt PORTC
INTERRUPT_DEFINITION(EXTI_PORTC_IRQHandler, 5);
// External Interrupt PORTD
INTERRUPT_DEFINITION(EXTI_PORTD_IRQHandler, 6);
// External Interrupt PORTE
INTERRUPT_DEFINITION(EXTI_PORTE_IRQHandler, 7);
#ifdef STM8S903
// External Interrupt PORTF
INTERRUPT_DEFINITION(EXTI_PORTF_IRQHandler, 8);
#endif // STM8S903
#if defined (STM8S208) || defined (STM8AF52Ax)
// CAN RX Interrupt routine.
INTERRUPT_DEFINITION(CAN_RX_IRQHandler, 8);
// CAN TX Interrupt routine.
INTERRUPT_DEFINITION(CAN_TX_IRQHandler, 9);
#endif // STM8S208 || STM8AF52Ax
// SPI Interrupt routine.
INTERRUPT_DEFINITION(SPI_IRQHandler, 10);
// Timer1 Update/Overflow/Trigger/Break Interrupt
INTERRUPT_DEFINITION(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11);
// Timer1 Capture/Compare Interrupt routine.
INTERRUPT_DEFINITION(TIM1_CAP_COM_IRQHandler, 12);
#ifdef STM8S903
// Timer5 Update/Overflow/Break/Trigger Interrupt
INTERRUPT_DEFINITION(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13);
// Timer5 Capture/Compare Interrupt
INTERRUPT_DEFINITION(TIM5_CAP_COM_IRQHandler, 14);
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
// Timer2 Update/Overflow/Break Interrupt
INTERRUPT_DEFINITION(TIM2_UPD_OVF_BRK_IRQHandler, 13);
// Timer2 Capture/Compare Interrupt
INTERRUPT_DEFINITION(TIM2_CAP_COM_IRQHandler, 14);
#endif // STM8S903
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \
defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x)
// Timer3 Update/Overflow/Break Interrupt
INTERRUPT_DEFINITION(TIM3_UPD_OVF_BRK_IRQHandler, 15);
// Timer3 Capture/Compare Interrupt
INTERRUPT_DEFINITION(TIM3_CAP_COM_IRQHandler, 16);
#endif // STM8S208, STM8S207 or STM8S105 or STM8AF62Ax or STM8AF52Ax or STM8AF626x
#if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \
defined(STM8S003) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903)
// UART1 TX Interrupt
INTERRUPT_DEFINITION(UART1_TX_IRQHandler, 17);
// UART1 RX Interrupt
INTERRUPT_DEFINITION(UART1_RX_IRQHandler, 18);
#endif // STM8S208 or STM8S207 or STM8S103 or STM8S903 or STM8AF62Ax or STM8AF52Ax
// I2C Interrupt
INTERRUPT_DEFINITION(I2C_IRQHandler, 19);
#if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x)
// UART2 TX interrupt
INTERRUPT_DEFINITION(UART2_TX_IRQHandler, 20);
// UART2 RX interrupt
INTERRUPT_DEFINITION(UART2_RX_IRQHandler, 21);
#endif // STM8S105 or STM8AF626x
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// UART3 TX interrupt
INTERRUPT_DEFINITION(UART3_TX_IRQHandler, 20);
// UART3 RX interrupt
INTERRUPT_DEFINITION(UART3_RX_IRQHandler, 21);
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
// ADC2 interrupt
INTERRUPT_DEFINITION(ADC2_IRQHandler, 22);
#else // STM8S105, STM8S103 or STM8S903 or STM8AF626x
// ADC1 interrupt
INTERRUPT_DEFINITION(ADC1_IRQHandler, 22);
#endif // STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax
#ifdef STM8S903
// Timer6 Update/Overflow/Trigger Interrupt
INTERRUPT_DEFINITION(TIM6_UPD_OVF_TRG_IRQHandler, 23);
#else // STM8S208, STM8S207, STM8S105 or STM8S103 or STM8AF52Ax or STM8AF62Ax or STM8AF626x
// Timer4 Update/Overflow Interrupt
INTERRUPT_DEFINITION(TIM4_UPD_OVF_IRQHandler, 23);
#endif // STM8S903
// Eeprom EEC Interrupt
INTERRUPT_DEFINITION(EEPROM_EEC_IRQHandler, 24);
#endif // __INTERRUPTS_H__

View File

@@ -0,0 +1,287 @@
/*
* led.c
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "stm8l.h"
#include "led.h"
/*
* bits no 7 6 5 4 3 2 1 0
* dec value 128 64 32 16 8 4 2 1
*/
/********** current variant **********/
/*
* One digit: TABLE:
* ***A*** 0 1 2 3 4 5 6 7 8 9 A B C D E F - h
* * * (F) PB4 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0
* F B (B) PB5 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1
* * * (A) PC3 0 1 0 0 1 0 0 0 0 0 0 1 0 1 0 0 1 1
* ***G*** (G) PC7 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0
* * * (C) PD1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0
* E C (DP)PC6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
* * * ** (D) PC5 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 1
* ***D*** *DP* (E) PC4 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 0 1 0
* **
*/
/*
* BUTTONS (if BUTNS defined)
* 0 - PB4, 1 - PB5, 2 - PD1, 3..7 - PC3..PC7
* or:
* 0 - F(10), 1 - B(7), 2 - C(4), 3 - A(11), 4 - E(1), 5 - D(2), 6 - DP(3), 7 - G(5)
*/
#ifdef BUTNS
volatile U8 buttons_state;
#endif
/*
* Number of digit on indicator with common anode
* digis 0..2: PA3, PD4, PD5
*/
#define CLEAR_ANODES() do{PD_ODR &= ~(0x30);PA_ODR &= ~(0x08);}while(0)
/************* arrays for ports *************/
// PB, mask: 0x30, PB4:0x10=16, PB5:0x20=32
#define PB_BLANK 0x30
static U8 PB_bits[18] = {0,16,16,16,0,32,32,16,0,0,0,32,32,16,32,32,48,32};
// PC, mask: 0xF8, PC3:0x08=8, PC4:0x10=16, PC5:0x20=32, PC6:0x40=64, PC7:0x80=128
#define PC_BLANK 0xF8
//static U8 PC_bits[18] = {128,184,0,16,56,16,0,176,0,16,32,8,128,8,0,32,56,40};
static U8 PC_bits[18] = {192,248,64,80,120,80,64,240,64,80,96,72,192,72,64,96,120,104};
// PD, mask: 0x02, PD1
static U8 PD_bits[18] = {0,0,2,0,0,0,0,0,0,0,0,0,2,0,2,2,2,0};
#define PD_BLANK 0x02
/*
********************* GPIO (page 111) ********************
* Px_ODR - Output data register bits
* Px_IDR - Pin input values
* Px_DDR - Data direction bits (1 - output)
* Px_CR1 - DDR=0: 0 - floating, 1 - pull-up input; DDR=1: 0 - pseudo-open-drain, 1 - push-pull output [not for "T"]
* Px_CR2 - DDR=0: 0/1 - EXTI disabled/enabled; DDR=1: 0/1 - 2/10MHz
*
*/
/**
* Setup for writing a letter
* @param ltr - letter (0..17 for 0..F, - or h | 0x80 for DP, any other value for 'space')
*/
void write_letter(U8 ltr){
U8 L = ltr & 0x7f;
// process buttons attached to A1 and cathodes
#ifdef BUTNS
if(PA_DDR & 0x08){ // first digit was lighten up
// convert all cathodes to pullup inputs (CR1 is already in ones)
PB_DDR &= ~PB_BLANK;
PC_DDR &= ~PC_BLANK;
PD_DDR &= ~PD_BLANK;
// and turn anode into zero
//PA_ODR &= ~0x08;
}
#endif
// first turn all off
CLEAR_ANODES();
// light up all segments
PB_ODR &= ~PB_BLANK;
PC_ODR &= ~PC_BLANK;
PD_ODR &= ~PD_BLANK;
// now clear spare segments
if(L < 18){ // letter
PB_ODR |= PB_bits[L];
PC_ODR |= PC_bits[L];
PD_ODR |= PD_bits[L];
}else{ // space - turn all OFF
PB_ODR |= PB_BLANK;
PC_ODR |= PC_BLANK;
PD_ODR |= PD_BLANK;
}
if(ltr & 0x80){ // DP
PC_ODR &= ~GPIO_PIN6;
}
#ifdef BUTNS
if(PA_DDR & 0x08){ // first digit was lighten up
// now check button states: 0 - PB4, 1 - PB5, 2 - PD1, 3..7 - PC3..PC7
buttons_state =
((PB_IDR & PB_BLANK) >> 4) |
((PD_IDR & PD_BLANK) << 1) |
(PC_IDR & PC_BLANK);
PA_DDR &= ~0x08; // switch first anode to input
// and switch cathodes to output
PB_DDR |= PB_BLANK;
PC_DDR |= PC_BLANK;
PD_DDR |= PD_BLANK;
}
#endif
}
/**
* Turn on anode power for digit N (0..2: PA3, PD4, PD5 -- A0x08, D0x10, D0x20)
* @param N - number of digit (0..2), if other - no action (display off)
* @return
*/
void light_up_digit(U8 N){
switch(N){
case 0:
#ifdef BUTNS
PA_DDR |= 0x08; // switch to output
#endif
PA_ODR |= 0x08;
break;
case 1:
PD_ODR |= 0x10;
break;
case 2:
PD_ODR |= 0x20;
break;
}
}
static U8 display_buffer[3] = {' ',' ',' '}; // blank by default
static U8 N_current = 0; // current digit to display
/**
* fills buffer to display
* @param str - string to display, contains "0..f" for digits, " " for space, "." for DP
* for example: " 1.22" or "h1ab" (something like "0...abc" equivalent to "0.abc"
* register independent!
* any other letter would be omitted
* if NULL - fill buffer with spaces
*/
void set_display_buf(char *str){
U8 B[3];
char ch, M = 0, i;
N_current = 0; // refresh current digit number
// empty buffer
for(i = 0; i < 3; i++)
display_buffer[i] = ' ';
if(!str) return;
i = 0;
for(;(ch = *str) && (i < 3); str++){
M = 0;
if(ch > '/' && ch < ':'){ // digit
M = '0';
}else if(ch > '`' & ch < 'g'){ // a..f
M = 'a' - 10;
}else if(ch > '@' & ch < 'G'){ // A..F
M = 'A' - 10;
}else if(ch == '-'){ // minus
M = '-' - 16;
}else if(ch == 'h'){ // hex
M = 'h' - 17;
}else if(ch == 'H'){ // hex
M = 'H' - 17;
}else if(ch == '.'){ // DP, set it to previous char
if(i == 0){ // word starts from '.' - make a space with point
B[0] = 0xff;
}else{ // set point for previous character
B[i-1] |= 0x80;
}
continue;
}else if(ch != ' '){ // bad character - continue
continue;
}
B[i] = ch - M;
i++;
}
// now make align to right
ch = 2;
for(M = i-1; M > -1; M--, ch--){
display_buffer[ch] = B[M];
}
}
/**
* Show Nth digit of buffer (function ran by timer)
* @param N - number of digit in buffer (0..3)
*/
void show_buf_digit(U8 N){
if(N > 2) return;
write_letter(display_buffer[N]);
light_up_digit(N);
}
/**
* Show next digit - function calls from main() by some system time value amount
*/
void show_next_digit(){
show_buf_digit(N_current++);
if(N_current > 2) N_current = 0;
}
/**
* Turn off current digit: to change display brightness
*/
void lights_off(){
U8 N;
if(N_current) N = N_current - 1;
else N = 2;
light_up_digit(N);
}
/**
* convert integer value i into string and display it
* @param i - value to display, -99 <= i <= 999, if wrong, displays "---E"
*/
void display_int(int I, char voltmeter){
int rem;
U8 pos = 0; //DP position
char N = 2, sign = 0, i;
if(I < -99 || I > 999){
set_display_buf("--E");
return;
}
// prepare buffer for voltmeter's values
if(voltmeter){
for(i = 0; i < 3; i++)
display_buffer[i] = 0;
if(I>999){
I /= 10;
pos = 1; // DP is in 2nd position - voltage more than 9.99V
}
}else{
for(i = 0; i < 3; i++)
display_buffer[i] = ' ';
}
if(I == 0){ // just show zero
display_buffer[2] = 0;
return;
}
if(I < 0){
sign = 1;
I *= -1;
}
do{
rem = I % 10;
display_buffer[N] = rem;
I /= 10;
}while(--N > -1 && I);
if(sign && N > -1) display_buffer[N] = 16; // minus sign
if(voltmeter) display_buffer[pos] |= 0x80;
}
/**
* displays digital point at position i
* @param i - position to display DP, concequent calls can light up many DPs
*/
void display_DP_at_pos(U8 i){
if(i > 2) return;
display_buffer[i] |= 0x80;
}

View File

@@ -0,0 +1,47 @@
/*
* led.h
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __LED_H__
#define __LED_H__
#include "stm8l.h"
#ifdef BUTNS
extern volatile U8 buttons_state; // flags for button: 1 - pressed, 0 - not pressed
#endif
void set_display_buf(char *str);
void show_buf_digit(U8 N);
void show_next_digit();
void lights_off();
void display_int(int i, char voltmeter);
void display_DP_at_pos(U8 i);
/**
* Initialize ports
* PA3, PB4|5, PC3|4|5|6|7, PD1|4|5
*/
#define LED_init() do{ \
PA_DDR = 0x08; PB_DDR = 0x30; PC_DDR = 0xf8; PD_DDR = 0x32; \
PA_CR1 = 0x08; PB_CR1 = 0x30; PC_CR1 = 0xf8; PD_CR1 = 0x32; \
}while(0)
#endif // __LED_H__

View File

@@ -0,0 +1,136 @@
/*
* main.c
*
* Copyright 2014 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "main.h"
#include "interrupts.h"
#include "led.h"
/*
int temp;
#define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); }
#define PIX_SWAP(a,b) { temp=(a);(a)=(b);(b)=temp; }
int p[9]; // buffer for median filtering
int opt_med9(){
PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
PIX_SORT(p[0], p[1]) ; PIX_SORT(p[3], p[4]) ; PIX_SORT(p[6], p[7]) ;
PIX_SORT(p[1], p[2]) ; PIX_SORT(p[4], p[5]) ; PIX_SORT(p[7], p[8]) ;
PIX_SORT(p[0], p[3]) ; PIX_SORT(p[5], p[8]) ; PIX_SORT(p[4], p[7]) ;
PIX_SORT(p[3], p[6]) ; PIX_SORT(p[1], p[4]) ; PIX_SORT(p[2], p[5]) ;
PIX_SORT(p[4], p[7]) ; PIX_SORT(p[4], p[2]) ; PIX_SORT(p[6], p[4]) ;
PIX_SORT(p[4], p[2]) ; return(p[4]) ;
}
*/
U32 Global_time = 0L; // global time in ms
// one digit emitting time
#define LED_delay 1
// pause between buttons actions
#define BTNS_delay 30
int main() {
U32 T_LED = 0L; // time of last digit update
U32 T_time = 0L; // timer
U32 T_btns = 0L; // buttons timer
U8 old_btns_state = 0;
//U8 tmpva = 0;
// int pidx = 0; // index in median buffer
// long cntrin = 0, cntrcap = 0; // counters for average
// Configure clocking
CLK_CKDIVR = 0; // F_HSI = 16MHz, f_CPU = 16MHz
// Configure pins
CFG_GCR |= 1; // disable SWIM
LED_init();
CCR |= 0x28; // make shure that we are on level 3 - disabled SW priority
// Configure Timer1
// prescaler = f_{in}/f_{tim1} - 1
// set Timer1 to 1MHz: 16/1 - 1 = 15
TIM1_PSCRH = 0;
TIM1_PSCRL = 15; // LSB should be written last as it updates prescaler
// auto-reload each 1ms: TIM_ARR = 1000 = 0x03E8
TIM1_ARRH = 0x03;
TIM1_ARRL = 0xE8;
// interrupts: update
TIM1_IER = TIM_IER_UIE;
// auto-reload + interrupt on overflow + enable
TIM1_CR1 = TIM_CR1_APRE | TIM_CR1_URS | TIM_CR1_CEN;
// enable all interrupts
enableInterrupts();
set_display_buf("abc");
// Loop
do {
// onse per 300ms refresh displayed value
if(((unsigned int)(Global_time - T_time) > 300) || (T_time > Global_time)){
T_time = Global_time;
// display_int((int)tmpva++,0);
// cntrin = 0;cntrcap = 0;voltagein = 0L;voltagecap = 0L;pidx = 0;
}
if((U8)(Global_time - T_LED) > LED_delay){
T_LED = Global_time;
show_next_digit();
/*if(buttons_state != old_btns_state){ // user has pressed or released any button
;
old_btns_state = buttons_state;
}*/
}
if((U8)(Global_time - T_btns) > BTNS_delay){
T_btns = Global_time;
if(old_btns_state != buttons_state){
U8 pressed = old_btns_state & ~buttons_state; // pressed buttons are ones
if(pressed){ // display
//display_int(pressed, 0);
display_int(buttons_state, 0);
}else{ // some buttons released
if(buttons_state == 0xff){ // all buttons released
set_display_buf("abc");
}else{
display_int(~old_btns_state & buttons_state, 0); // released are ones
}
old_btns_state = buttons_state;
}
}
}
} while(1);
}
/*
if(ADC_ready){
// prepare data for rounded output
p[pidx] = ADC_value;
if(++pidx == 9){ // buffer is ready
if(vcap){
voltagecap += (long)(opt_med9());
cntrcap++;
ADC_CSR = 0x24; // switch to ain
vcap = 0;
}else{
voltagein += (long)(opt_med9());
cntrin++;
ADC_CSR = 0x26; // switch to vcap
vcap = 1;
}
pidx = 0;
}
ADC_ready = 0;
}
*/

View File

@@ -0,0 +1,30 @@
/*
* main.h
*
* Copyright 2015 Edward V. Emelianoff <eddy@sao.ru>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#pragma once
#ifndef __MAIN_H__
#define __MAIN_H__
#include "stm8l.h"
#define CONCAT(a,b) a##_##b
#define PORT(a,b) CONCAT(a,b)
#endif // __MAIN_H__

View File

@@ -0,0 +1,58 @@
:2080A000808080808080808080AE5255F644241B90CE000472A90001C60003A90097C60025
:1980C00002A9009590CF0004CF0002AE52557F808080808080808080805F
:208000008200808382000000820080A0820080A1820080A2820080A3820080A4820080A57E
:20802000820080A6820080A78200000082000000820080A8820080A9820080D0820080D1F1
:20804000820080D28200000082000000820080D3820080D4820080D58200000082000000C2
:20806000820080D6820080D7820080D88200000082000000820000008200000082000000EB
:1D808300AE00012707724F00005A26F9AE003E2709D68685D700015A26F7CC8080B1
:03808000CC80D9D8
:2080D900521D5F1F0C1F0A5F1F081F065F1F041F020F01AE50C67F72107F60AE5002A608B5
:2080F900F7AE5007A630F7AE500CA6F8F7AE5011A632F7AE5003A608F7AE5008A630F7AEFA
:20811900500DA6F8F7AE5012A632F7AE7F0AF6AA28F7AE52607FAE5261A60FF7AE5262A68B
:2081390003F7AE5263A6E8F7AE5254A601F7AE5250A685F79AAE822F1F1C1E1C89CD836D2C
:208159005B02CE000472F008C6000312076B19C600021206C600056B1790CE0003C60002B1
:208179006B14A3012C2211CE00041308C600031207C600021206240A17077B176B097B14D4
:208199006B06C60005887B0E6B14841013A101230D170B7B176B0D7B146B0ACD84BEC6007C
:2081B90005887B066B13841012A11E2395CE00041F04CE00021F027B01C100012603CC8163
:2081D9005BC600014314014D2711C60001974F954B0089CD84EC5B03CC815BC60001A1FFC7
:2081F900260A1E1C89CD836D5B02201F7B016B110F101E1053C600010F0E89140285979E45
:1A821900140E954B0089CD84EC5B03C600016B01CC815B5B1D81616263002B
:0486860000000000F0
:2082330052067B09A47F6B01AE5002F6A5082715AE5007F6A4CFF7AE500CF6A407F7AE50DC
:2082530011F6A4FDF7AE500FF6A4CFF7AE5000F6A4F7F7AE5005F6A4CFF7AE500AF6A4076D
:20827300F7AE500FF6A4FDF7AE5005F66B057B01A1122444AE00069F1B01979EA90095F681
:208293001A05AE5005F7AE500AF66B02AE00189F1B01979EA90095F61A02AE500AF7AE5044
:2082B3000FF66B04AE002A9F1B01979EA90095F61A04AE500FF720167B05AA30AE5005F78F
:2082D300AE500AF6AAF8F7AE500FF6AA02F77B09482407AE500AF6A4BFF7AE5002F69095E4
:2082F300A508273EAE5006F6A4304EA40F6B03AE5010F6A402481A036B06AE500BF6A4F801
:208313001A06C70001909EA4F7AE5002F7AE5007F6AA30F7AE500CF6AAF8F7AE5011F6AA8E
:2083330002F75B06817B03A100270E7B03A10127187B03A102271B2020AE5002F6AA08F75A
:20835300AE5000F6AA08F72010AE500FF6AA10F72007AE500FF6AA20F7815212725F003FA9
:20837300AE003C1F094F5F9772FB0988A620F7844CA1032FF11E152603CC849C965C5C1F8F
:20839300070F011615170B1E0BF66B06887B024A6B13844D2603CC84707B01A1032F03CC31
:2083B30084704F957B06A12F2D0C7B06A13A2E06A63095CC84557B06A1602C040F112004B2
:2083D300A6016B117B06A1672F034F2002A60114114D2706A65795CC84557B06A1402C042C
:2083F3000F102004A6016B107B06A1472F034F2002A60114104D2705A6379520457B06A1BC
:208413002D2605A61D95203A7B06A1682605A65795202F7B06A1482605A6379520247B06DD
:20843300A12E26180D0126071E07A6FFF720265F7B129772FB07F6AA80F720197B06A12051
:208453002613905F7B01909772F9077B068910018590F70C011E0B5C1F0BCC839A7B126B08
:20847300057B056B0FA6026B067B0FA1FF2D1A5F7B069772FB091F0D5F7B0F9772FB07F65D
:208493001E0DF70A0F0A0620E05B12817B03A1022218AE003C9F1B03979EA90095F688CDD0
:2084B3008233847B0388CD83388481C6003F95725C003F9E88CD849F84C6003FA1022304CD
:2084D300725F003F81725D003F2706C6003F4A2002A60288CD83388481520A0F030F011EF3
:2084F3000DA3FF9D2F131E0DA303E72C040F082004A6016B080D08270CAE85EF89CD836DEE
:208513005B02CC85D70D0F2729AE003C1F044F5F9772FB047F4CA1032FF50D0827294B0A47
:208533004B001E0F89CD86315B041F0DA6016B032015AE003C1F064F5F9772FB0688A620B9
:20855300F7844CA1032FF11E0D2607AE003E7FCC85D71E0DA300002E09A6016B011E0D50FF
:208573001F0DAE003C1F09A6026B024B0A4B001E0F89CD85F35B04905F7B02909772F90994
:208593009F90F74B0A4B001E0F89CD86315B041F0D0A027B02A1FF2C034F2002A6014D2759
:2085B300041E0D26C60D01270D4D270A5F7B029772FB09A610F70D0F270A5F7B039772FB09
:2085D300097999765B0A817B03A102220EAE003C9F1B03979EA90095799976812D2D4500FE
:20868A00001010100020201000000020201020203020C0F84050785040F040506048C048F0
:1A86AA004060786800000200000000000000000002000202020020202000CC
:2085F30052051E08A300002F040F012004A6016B010D0127051E085020021E081F041E0A8B
:20861300A300002E071E0A501F022004160A170216021E0465930D012701505B0581520886
:208633001E0BA300002F040F052004A6016B050D0527051E0B5020021E0B1F011E0DA300E9
:20865300002F040F062004A6016B060D0627107B0E406B044F120D6B0316031707200416B4
:138673000D170716071E01657B0518064D2701505B0881E1
:00000001FF