mirror of
https://github.com/eddyem/STM8_samples.git
synced 2026-01-31 20:35:12 +03:00
add 1-wire
This commit is contained in:
parent
1a0095a9ae
commit
b861211e29
34
1-wire/Makefile
Normal file
34
1-wire/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
NAME=testproj
|
||||
SDCC=sdcc
|
||||
|
||||
CCFLAGS=-DSTM8S105 -I../ -I/usr/share/sdcc/include -mstm8 --out-fmt-ihx
|
||||
LDFLAGS= -mstm8 --out-fmt-ihx -lstm8
|
||||
FLASHFLAGS=-cstlinkv2 -pstm8s105
|
||||
|
||||
SRC=$(wildcard *.c)
|
||||
# ATTENTION: FIRST in list should be file with main()
|
||||
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 ports_definition.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
|
||||
BIN
1-wire/client
Executable file
BIN
1-wire/client
Executable file
Binary file not shown.
197
1-wire/interrupts.c
Normal file
197
1-wire/interrupts.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* interrupts.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 "ports_definition.h"
|
||||
#include "uart.h"
|
||||
#include "onewire.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){
|
||||
}
|
||||
|
||||
// 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
|
||||
// manage with sending/receiving
|
||||
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14){
|
||||
if(TIM2_SR1 & TIM_SR1_CC1IF){
|
||||
TIM2_SR1 &= ~TIM_SR1_CC1IF;
|
||||
onewire_gotlen = TIM2_CCR1H << 8;
|
||||
onewire_gotlen |= TIM2_CCR1L;
|
||||
if(onewire_tick_ctr){ // there's some more data to transmit / receive
|
||||
--onewire_tick_ctr;
|
||||
if(is_receiver){// receive bits
|
||||
ow_data >>= 1;
|
||||
if(onewire_gotlen < ONE_ZERO_BARRIER){ // this is 1
|
||||
ow_data |= 0x80; // LSbit first!
|
||||
}
|
||||
// in receiver mode we don't need to send byte after ctr is zero!
|
||||
if(onewire_tick_ctr == 0){
|
||||
TIM2_CR1 &= ~TIM_CR1_CEN;
|
||||
}
|
||||
}else{// transmit bits
|
||||
// update CCR2 registers with new values
|
||||
if(ow_data & 1){ // transmit 1
|
||||
TIM2REG(CCR2, BIT_ONE_P);
|
||||
}else{ // transmit 0
|
||||
TIM2REG(CCR2, BIT_ZERO_P);
|
||||
}
|
||||
ow_data >>= 1;
|
||||
}
|
||||
}else{ // end: turn off timer
|
||||
TIM2_CR1 &= ~TIM_CR1_CEN;
|
||||
}
|
||||
}
|
||||
//if(TIM2_SR1 & TIM_SR1_CC2IF)
|
||||
// TIM2_SR1 &= ~TIM_SR1_CC2IF;
|
||||
}
|
||||
#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){
|
||||
U8 rb;
|
||||
if(UART2_SR & UART_SR_RXNE){ // data received
|
||||
rb = UART2_DR; // read received byte & clear RXNE flag
|
||||
while(!(UART2_SR & UART_SR_TXE));
|
||||
UART2_DR = rb; // echo received symbol
|
||||
UART_rx[UART_rx_cur_i++] = rb; // put received byte into cycled buffer
|
||||
if(UART_rx_cur_i == UART_rx_start_i){ // Oops: buffer overflow! Just forget old data
|
||||
UART_rx_start_i++;
|
||||
check_UART_pointer(UART_rx_start_i);
|
||||
}
|
||||
check_UART_pointer(UART_rx_cur_i);
|
||||
}
|
||||
}
|
||||
#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){
|
||||
if(TIM4_SR & TIM_SR1_UIF){ // update interrupt
|
||||
Global_time++; // increase timer
|
||||
}
|
||||
TIM4_SR = 0; // clear all interrupt flags
|
||||
}
|
||||
#endif // STM8S903
|
||||
|
||||
// Eeprom EEC Interrupt
|
||||
INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24){}
|
||||
144
1-wire/interrupts.h
Normal file
144
1-wire/interrupts.h
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
// 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__
|
||||
144
1-wire/main.c
Normal file
144
1-wire/main.c
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* blinky.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 "ports_definition.h"
|
||||
#include "interrupts.h"
|
||||
#include "uart.h"
|
||||
#include "onewire.h"
|
||||
|
||||
volatile unsigned long Global_time = 0L; // global time in ms
|
||||
U16 paused_val = 500; // interval between LED flashing
|
||||
volatile U8 waitforread = 0;
|
||||
|
||||
// show received scrtchpad
|
||||
void show_received_data(){
|
||||
char i;
|
||||
// uart_write("show_received_data()\n");
|
||||
for(i = 8; i > -1; i--){
|
||||
if(i < 8) UART_send_byte(',');
|
||||
printUHEX(ow_data_array[i]);
|
||||
}
|
||||
ow_process_resdata = NULL;
|
||||
uart_write("\nTemp: ");
|
||||
print_long(gettemp());
|
||||
uart_write("dergC\n");
|
||||
}
|
||||
|
||||
// ask to read N bytes after temper request
|
||||
void send_read_seq(){
|
||||
// uart_write("send_read_seq()\n");
|
||||
onewire_receive_bytes(9);
|
||||
ow_process_resdata = show_received_data;
|
||||
}
|
||||
|
||||
void wait_reading(){
|
||||
// uart_write("wait_reading()\n");
|
||||
waitforread = 1;
|
||||
ow_process_resdata = NULL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
unsigned long T = 0L;
|
||||
// int Ival;
|
||||
U8 rb;
|
||||
CFG_GCR |= 1; // disable SWIM
|
||||
// Configure clocking
|
||||
CLK_CKDIVR = 0; // F_HSI = 16MHz, f_CPU = 16MHz
|
||||
|
||||
// Timer 4 (8 bit) used as system tick timer
|
||||
// prescaler == 128 (2^7), Tfreq = 125kHz
|
||||
// period = 1ms, so ARR = 125
|
||||
TIM4_PSCR = 7;
|
||||
TIM4_ARR = 125;
|
||||
// interrupts: update
|
||||
TIM4_IER = TIM_IER_UIE;
|
||||
// auto-reload + interrupt on overflow + enable
|
||||
TIM4_CR1 = TIM_CR1_APRE | TIM_CR1_URS | TIM_CR1_CEN;
|
||||
|
||||
// PC2 - PP output (on-board LED)
|
||||
PORT(LED_PORT, DDR) |= LED_PIN;
|
||||
PORT(LED_PORT, CR1) |= LED_PIN;
|
||||
|
||||
uart_init();
|
||||
|
||||
onewire_setup();
|
||||
|
||||
// enable all interrupts
|
||||
enableInterrupts();
|
||||
|
||||
// Loop
|
||||
do{
|
||||
if((Global_time - T > paused_val) || (T > Global_time)){
|
||||
T = Global_time;
|
||||
PORT(LED_PORT, ODR) ^= LED_PIN; // blink on-board LED
|
||||
if(!OW_CONVERSION_DONE) uart_write("conversion in process\n");
|
||||
}
|
||||
process_onewire();
|
||||
if(UART_read_byte(&rb)){ // buffer isn't empty
|
||||
switch(rb){
|
||||
case 'h': // help
|
||||
case 'H':
|
||||
uart_write("\nPROTO:\n+/-\tLED period\nS/s\tset/get Mspeed\n"
|
||||
"r: reset 1-wire\n"
|
||||
"w: read temper\n");
|
||||
break;
|
||||
case '+':
|
||||
paused_val += 100;
|
||||
if(paused_val > 10000)
|
||||
paused_val = 500; // but not more than 10s
|
||||
break;
|
||||
case '-':
|
||||
paused_val -= 100;
|
||||
if(paused_val < 500) // but not less than 0.5s
|
||||
paused_val = 500;
|
||||
break;
|
||||
case 'r':
|
||||
if(!onewire_reset()) uart_write("not ");
|
||||
uart_write("found 1-wire devices (echo len: ");
|
||||
print_long((long)onewire_gotlen);
|
||||
uart_write(")\n");
|
||||
break;
|
||||
case 'w':
|
||||
if(!onewire_reset()){
|
||||
uart_write("no devices found!");
|
||||
break;
|
||||
}
|
||||
ow_data_array[0] = OW_CONVERT_T;
|
||||
ow_data_array[1] = OW_SKIP_ROM;
|
||||
ow_process_resdata = wait_reading;
|
||||
onewire_send_bytes(2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(waitforread){
|
||||
if(OW_CONVERSION_DONE){
|
||||
if(onewire_reset()){
|
||||
waitforread = 0;
|
||||
ow_process_resdata = send_read_seq;
|
||||
ow_data_array[0] = OW_READ_SCRATCHPAD;
|
||||
ow_data_array[1] = OW_SKIP_ROM;
|
||||
onewire_send_bytes(2);
|
||||
}else uart_write("error reseting!");
|
||||
}
|
||||
}
|
||||
}while(1);
|
||||
}
|
||||
|
||||
|
||||
257
1-wire/onewire.c
Normal file
257
1-wire/onewire.c
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
* onewire.c
|
||||
*
|
||||
* Copyright 2015 Edward V. Emelianoff <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
* 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 "onewire.h"
|
||||
#include "ports_definition.h"
|
||||
#include "uart.h"
|
||||
|
||||
// mode of 1-wire
|
||||
volatile OW_modes ow_mode = OW_MODE_OFF;
|
||||
// length of zero-pulse (TIM2_CCR1)
|
||||
volatile U16 onewire_gotlen = 0;
|
||||
volatile U8 is_receiver = 0;
|
||||
volatile U8 ow_data;
|
||||
// remaining ticks counter
|
||||
volatile U8 onewire_tick_ctr;
|
||||
// array for sending/receiving data
|
||||
// DATA STORED IN REVERCE ORDER! FIRST BYTE ID ow_data_array[N] AND LAST IS ow_data_array[0]!!!
|
||||
U8 ow_data_array[10];
|
||||
// how much bytes to send/receive
|
||||
U8 ow_byte_ctr;
|
||||
// this function will be called after receiving/transmitting of N bytes
|
||||
// inside this function should be: ow_process_resdata = NULL;
|
||||
void (*ow_process_resdata)() = NULL;
|
||||
|
||||
|
||||
/*
|
||||
********************* Timer2 ********************
|
||||
* prescaler: TIM2_PSCR f = f_{in}/2^{TIM2_PSCR}
|
||||
* other registers:
|
||||
* TIM2_CR1 (page 223): | ARPE | reserved[2:0] | OPM | URS | UDIS | CEN |
|
||||
* ARPE - Auto-reload preload enable (for TIM2_ARR)
|
||||
* OPM: One-pulse mode (not implemented!)
|
||||
* URS: Update request source (When enabled by the UDIS bit, 1 - interrupt only on counter overflow/underflow)
|
||||
* UDIS: Update disable (1 - disable update int)
|
||||
* CEN: Counter enable (1 - enable)
|
||||
* TIM2_IER (page 226): | res | TIE | res | res | CC3IE | CC2IE | CC1IE | UIE |
|
||||
* T - trigger; CC - comp/capt; U - update <--
|
||||
* TIM2_SR1 (page 227): similar (but instead of IE -> IF)
|
||||
* interrupt flags
|
||||
* TIM2_SR2 (page 228): overcapture flags
|
||||
* TIM2_EGR (page 229): event generation
|
||||
* TIM2_CCMR1 (page 230):
|
||||
* OUTPUT: | res | OC1M[2:0] | OC1PE | res | CC1S[1:0] |
|
||||
* INPUT: | IC1F[3:0] | IC1PSC[1:0] | CC1S[1:0] |
|
||||
* OC1M: compare mode !!! writeable only when channel is off (CC1E=0) !!!
|
||||
* 000: no
|
||||
* 001: set channel 1 to active level on match
|
||||
* 010: set chan1 to inactive ...
|
||||
* 011: toggle
|
||||
* 100: force 0
|
||||
* 101: force 1
|
||||
* 110: PWM mode 1 (1->0)
|
||||
* 111: PWM mode 2 (0->1)
|
||||
* OC1PE: output compare 1 preload enable (0 - loads immediately)
|
||||
* CC1S: comp/capt selection
|
||||
* 00: CC1 is out
|
||||
* 01: CC1 is in (TI1FP1)
|
||||
* 10: TI2FP1
|
||||
* 11: (only for TIM5)
|
||||
* IC1F: input capture filter (0 - no filter)
|
||||
* IC1PSC: capture prescaler (0 - no, xx - 2^{xx} events)
|
||||
* TIM2_CCMRx - the same for channels 2 & 3
|
||||
* TIM2_CCERx - CC polarity/enable (lowest 2 bytes in each 4): P=1:active high/capture on rising edge;
|
||||
* TIM2_CNTRH, TIM2_CNTRL - counter value (automatical)
|
||||
* TIM2_PSCR - prescaler value, lower 4 bits
|
||||
* TIM1_ARRH, TIM1_ARRL - auto-reload value (while zero, timer is stopped) (page 206)
|
||||
* TIM2_CCRxL/H - compare/capture registers
|
||||
*/
|
||||
|
||||
void onewire_setup(){
|
||||
// freq = 1MHz: psc=16 -> TIM2_PSCR = 4
|
||||
TIM2_PSCR = 4;
|
||||
// AIN: PD3 / TIM2_CH2 -> CC1 will be input on TI2FP1 & CC2 will be output
|
||||
// configure pin CC2 (PD3): open-drain output
|
||||
PORT(PD, DDR) |= GPIO_PIN3; // output & pseudo open-drain
|
||||
PORT(PD, CR2) |= GPIO_PIN3; // fast
|
||||
// out: PWM mode 1 (active -> inactive), preload enable
|
||||
// CCMR2: | 0 | 110 | 1 | 0 | 00 |
|
||||
TIM2_CCMR2 = 0x68;
|
||||
// in: TI2FP1
|
||||
TIM2_CCMR1 = 0x02;
|
||||
// polarity: out - active LOW, in - capture on rising edge, enable
|
||||
TIM2_CCER1 = 0x31;
|
||||
// interrupts: CC1IE
|
||||
TIM2_IER = TIM_IER_CC1IE;
|
||||
// enable preload for registers to refresh their values only by UEV
|
||||
TIM2_CR1 = TIM_CR1_APRE | TIM_CR1_URS;
|
||||
// ARR values: 1000 for reset, 70 for data in/out
|
||||
// CCR2 values: 500 for reset, 60 for sending 0 or reading, <15 for sending 1
|
||||
// CCR1 values: >550 if there's devices on line (on reset), >12 (typ.15) - read 0, < 12 (typ.1) - read 1
|
||||
// WARN! on reset there would be two CC events generated
|
||||
}
|
||||
|
||||
/**
|
||||
* reset 1-wire bus
|
||||
* return 0 if no devices found, else return 1
|
||||
*/
|
||||
U8 onewire_reset(){
|
||||
is_receiver = 0; // send data, not receive
|
||||
onewire_tick_ctr = 1; // if there's devices on the bus CC1 int would be generated twice!
|
||||
TIM2REG(ARR, RESET_LEN);
|
||||
TIM2REG(CCR2, RESET_P);
|
||||
//TIM2_CCR1H = TIM2_CCR1L = 0;
|
||||
TIM2_EGR = TIM_EGR_UG; // generate UEV to update values
|
||||
TIM2_CR1 |= TIM_CR1_CEN; // turn on timer
|
||||
ow_mode = OW_MODE_RESET;
|
||||
while(OW_BUSY); // wait until transmission is over
|
||||
return ((onewire_gotlen > RESET_BARRIER) ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send one byte through 1-wire
|
||||
*/
|
||||
void onewire_send_byte(U8 byte){
|
||||
ow_data = byte;
|
||||
is_receiver = 0;
|
||||
onewire_tick_ctr = 7; // 7 bits remain
|
||||
TIM2REG(ARR, BIT_LEN);
|
||||
if(ow_data & 1){ // transmit 1
|
||||
TIM2REG(CCR2, BIT_ONE_P);
|
||||
}else{ // transmit 0
|
||||
TIM2REG(CCR2, BIT_ZERO_P);
|
||||
}
|
||||
TIM2_EGR = TIM_EGR_UG; // generate UEV to update values
|
||||
ow_data >>= 1;
|
||||
TIM2_CR1 |= TIM_CR1_CEN; // turn on timer
|
||||
}
|
||||
|
||||
/**
|
||||
* get 1 byte through 1-wire
|
||||
*/
|
||||
void onewire_wait_for_receive(){
|
||||
ow_data = 0;
|
||||
is_receiver = 1;
|
||||
onewire_tick_ctr = 8; // eight bits remain!
|
||||
TIM2REG(ARR, BIT_LEN);
|
||||
TIM2REG(CCR2, BIT_READ_P); // reading length
|
||||
TIM2_EGR = TIM_EGR_UG; // generate UEV to update values
|
||||
TIM2_CR1 |= TIM_CR1_CEN; // turn on timer
|
||||
}
|
||||
|
||||
// DATA STORED IN REVERCE ORDER! FIRST BYTE ID ow_data_array[N] AND LAST IS ow_data_array[0]!!!
|
||||
/**
|
||||
* wait for receiveing N bytes from 1-wire
|
||||
* N shoud be not great than 10
|
||||
*/
|
||||
void onewire_receive_bytes(U8 N){
|
||||
ow_byte_ctr = N;
|
||||
ow_mode = OW_MODE_RECEIVE_N;
|
||||
onewire_wait_for_receive();
|
||||
}
|
||||
|
||||
void onewire_send_bytes(U8 N){
|
||||
ow_byte_ctr = N;
|
||||
ow_mode = OW_MODE_TRANSMIT_N; // first data portion will be send by process_onewire
|
||||
}
|
||||
|
||||
/**
|
||||
* process 1-wire events
|
||||
*/
|
||||
void process_onewire(){
|
||||
if(OW_BUSY || !OW_CONVERSION_DONE) return; // let data to be processed
|
||||
switch(ow_mode){
|
||||
case OW_MODE_RECEIVE_N: // wait for receiving of N bytes -> send next byte
|
||||
|
||||
uart_write("receive ");
|
||||
printUHEX(ow_data);
|
||||
UART_send_byte(' ');
|
||||
printUHEX(onewire_gotlen);
|
||||
UART_send_byte('\n');
|
||||
|
||||
ow_data_array[--ow_byte_ctr] = ow_data;
|
||||
if(ow_byte_ctr){ // there's some more data to receive
|
||||
onewire_wait_for_receive(); // wait for another byte
|
||||
return;
|
||||
}
|
||||
// we have received all data - process it!
|
||||
ow_mode = OW_MODE_OFF;
|
||||
if(ow_process_resdata){
|
||||
ow_process_resdata();
|
||||
}
|
||||
break;
|
||||
case OW_MODE_TRANSMIT_N:
|
||||
uart_write("transmit ");
|
||||
if(ow_byte_ctr){ // we have some more data to transmit
|
||||
printUHEX(ow_data_array[ow_byte_ctr-1]);
|
||||
UART_send_byte('\n');
|
||||
onewire_send_byte(ow_data_array[--ow_byte_ctr]);
|
||||
return;
|
||||
}
|
||||
ow_mode = OW_MODE_OFF;
|
||||
uart_write("is over\n");
|
||||
if(ow_process_resdata){
|
||||
ow_process_resdata();
|
||||
}
|
||||
break;
|
||||
case OW_MODE_RESET:
|
||||
uart_write("reset done!\n");
|
||||
ow_mode = OW_MODE_OFF;
|
||||
break;
|
||||
default: // OW_MODE_OFF
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* convert temperature from ow_data_array (scratchpad)
|
||||
* in case of error return 200000
|
||||
* return value in 1000th degrees centigrade
|
||||
* don't forget that bytes in ow_data_array have reverce order!!!
|
||||
* so:
|
||||
* 8 - themperature LSB
|
||||
* 7 - themperature MSB (all higher bits are sign)
|
||||
* 6 - T_H
|
||||
* 5 - T_L
|
||||
* 4 - B20: Configuration register (only bits 6/5 valid: 9..12 bits resolution); 0xff for S20
|
||||
* 3 - 0xff (reserved)
|
||||
* 2 - (reserved for B20); S20: COUNT_REMAIN (0x0c)
|
||||
* 1 - COUNT PER DEGR (0x10)
|
||||
* 0 - CRC
|
||||
*/
|
||||
long gettemp(){
|
||||
// detect DS18S20
|
||||
long t;
|
||||
U8 l,m;
|
||||
char v;
|
||||
if(ow_data_array[4] == 0xff){ // DS18S20
|
||||
;
|
||||
}
|
||||
else{
|
||||
m = ow_data_array[7];
|
||||
l = ow_data_array[8];
|
||||
v = l>>4 | ((m & 7)<<4);
|
||||
if(m&0x80){ // minus
|
||||
v |= 0x80;
|
||||
}
|
||||
t = ((long)v) * 1000 + ((long)l&0x0f)*125;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
123
1-wire/onewire.h
Normal file
123
1-wire/onewire.h
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* onewire.h
|
||||
*
|
||||
* Copyright 2015 Edward V. Emelianoff <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
* 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 __ONEWIRE_H__
|
||||
#define __ONEWIRE_H__
|
||||
|
||||
#include "stm8l.h"
|
||||
|
||||
#define TIM2REGH(reg) TIM2_##reg##H
|
||||
#define TIM2REGL(reg) TIM2_##reg##L
|
||||
#define TIM2REG(reg, val) do{TIM2REGH(reg) = val >> 8; TIM2REGL(reg) = val & 0xff;}while(0)
|
||||
|
||||
|
||||
// ARR values: 1000 for reset, 100 for data in/out
|
||||
// CCR2 values: 500 for reset, 60 for sending 0 or reading, <15 for sending 1
|
||||
// CCR1 values: >550 if there's devices on line (on reset), >12 (typ.15) - read 0, < 12 (typ.1) - read 1
|
||||
#define RESET_LEN ((U16)1000)
|
||||
#define BIT_LEN ((U16)100)
|
||||
#define RESET_P ((U16)500)
|
||||
#define BIT_ONE_P ((U16)10)
|
||||
#define BIT_ZERO_P ((U16)60)
|
||||
#define BIT_READ_P ((U16)5)
|
||||
#define RESET_BARRIER ((U16)550)
|
||||
#define ONE_ZERO_BARRIER ((U16)10)
|
||||
|
||||
#define OW_CONVERSION_DONE ((PORT(PD,IDR) & GPIO_PIN3))
|
||||
#define OW_BUSY ((TIM2_CR1 & TIM_CR1_CEN))
|
||||
|
||||
|
||||
/*
|
||||
* thermometer commands
|
||||
* send them with bus reset!
|
||||
*/
|
||||
// find devices
|
||||
#define OW_SEARCH_ROM (0xf0)
|
||||
// read device (when it is alone on the bus)
|
||||
#define OW_READ_ROM (0x33)
|
||||
// send device ID (after this command - 8 bytes of ID)
|
||||
#define OW_MATCH_ROM (0x55)
|
||||
// broadcast command
|
||||
#define OW_SKIP_ROM (0xcc)
|
||||
// find devices with critical conditions
|
||||
#define OW_ALARM_SEARCH (0xec)
|
||||
/*
|
||||
* thermometer functions
|
||||
* send them without bus reset!
|
||||
*/
|
||||
// start themperature reading
|
||||
#define OW_CONVERT_T (0x44)
|
||||
// write critical temperature to device's RAM
|
||||
#define OW_SCRATCHPAD (0x4e)
|
||||
// read whole device flash
|
||||
#define OW_READ_SCRATCHPAD (0xbe)
|
||||
// copy critical themperature from device's RAM to its EEPROM
|
||||
#define OW_COPY_SCRATCHPAD (0x48)
|
||||
// copy critical themperature from EEPROM to RAM (when power on this operation runs automatically)
|
||||
#define OW_RECALL_E2 (0xb8)
|
||||
// check whether there is devices wich power up from bus
|
||||
#define OW_READ_POWER_SUPPLY (0xb4)
|
||||
|
||||
/*
|
||||
* RAM register:
|
||||
* 0 - themperature LSB
|
||||
* 1 - themperature MSB (all higher bits are sign)
|
||||
* 2 - T_H
|
||||
* 3 - T_L
|
||||
* 4 - B20: Configuration register (only bits 6/5 valid: 9..12 bits resolution); 0xff for S20
|
||||
* 5 - 0xff (reserved)
|
||||
* 6 - (reserved for B20); S20: COUNT_REMAIN (0x0c)
|
||||
* 7 - COUNT PER DEGR (0x10)
|
||||
* 8 - CRC
|
||||
*
|
||||
* To identify S20/B20 use value of confuguration register: its MSbit is 0
|
||||
*/
|
||||
|
||||
typedef enum{
|
||||
OW_MODE_OFF, // sleeping
|
||||
OW_MODE_TRANSMIT_N, // transmit N bytes
|
||||
OW_MODE_RECEIVE_N, // receive N bytes
|
||||
OW_MODE_RESET // reset bus
|
||||
} OW_modes;
|
||||
|
||||
|
||||
extern volatile U8 ow_data; // byte to send/receive
|
||||
extern volatile U8 onewire_tick_ctr; // tick counter
|
||||
extern volatile U8 is_receiver;
|
||||
extern volatile U16 onewire_gotlen; // last captured value
|
||||
extern U8 ow_data_array[];
|
||||
extern U8 ow_byte_ctr;
|
||||
extern volatile OW_modes ow_mode;
|
||||
|
||||
extern void (*ow_process_resdata)();
|
||||
|
||||
void onewire_setup();
|
||||
U8 onewire_reset();
|
||||
void onewire_send_byte(U8 byte);
|
||||
void onewire_wait_for_receive();
|
||||
void process_onewire();
|
||||
void onewire_receive_bytes(U8 N);
|
||||
void onewire_send_bytes(U8 N);
|
||||
|
||||
long gettemp();
|
||||
|
||||
#endif // __ONEWIRE_H__
|
||||
40
1-wire/ports_definition.h
Normal file
40
1-wire/ports_definition.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* ports_definition.h - definition of ports pins & so on
|
||||
*
|
||||
* Copyright 2014 Edward V. Emelianov <eddy@sao.ru, edward.emelianoff@gmail.com>
|
||||
*
|
||||
* 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 __PORTS_DEFINITION_H__
|
||||
#define __PORTS_DEFINITION_H__
|
||||
|
||||
#include "stm8l.h"
|
||||
|
||||
// macro for using in port constructions like PORT(LED_PORT, ODR) = xx
|
||||
#define CONCAT(a, b) a ## _ ## b
|
||||
#define PORT(a, b) CONCAT(a , b)
|
||||
|
||||
// on-board LED
|
||||
#define LED_PORT PC
|
||||
#define LED_PIN GPIO_PIN2
|
||||
|
||||
// UART2_TX
|
||||
#define UART_PORT PD
|
||||
#define UART_TX_PIN GPIO_PIN5
|
||||
|
||||
#endif // __PORTS_DEFINITION_H__
|
||||
123
1-wire/testproj.ihx
Normal file
123
1-wire/testproj.ihx
Normal file
@ -0,0 +1,123 @@
|
||||
:2080A0008080808080808080808080805202AE5302F66B017B01A5022603CC81527B016B35
|
||||
:2080C000027B02A4FDAE5302F7AE530FF65F975858585858585858CF0019AE5310F6974FF5
|
||||
:2080E000CA0019959FCA001A97CF0019725D000A2759C6000A4AC7000A725D001B2726C6C5
|
||||
:20810000000944C70009CE0019A3000A2408C60009AA80C70009725D000A2636AE5300F68D
|
||||
:20812000A4FEF7202D7200000902200CAE53117FAE5312A60AF7200AAE53117FAE5312A6F1
|
||||
:208140003CF7C6000944C700092007AE5300F6A4FEF75B0280808080805204AE5240F66B7E
|
||||
:20816000047B04A520274DAE5241F66B017B04A4804D27FDAE52417B01F7AE00011F02C642
|
||||
:20818000001797C600174CC700174F9572FB027B01F7C60016C10017260FC600164CC7008C
|
||||
:2081A00016A1082604725F0016C60017A1082604725F00175B048080AE5342F644241B90AC
|
||||
:2081C000CE002072A90001C6001FA90097C6001EA9009590CF0020CF001EAE53427F808020
|
||||
:2081E000AE5240F64824F9AE52417B03F781160390F64D2718AE5240F64824F9AE5245F6AC
|
||||
:20820000AA08F790F6905CAE5241F720E3815202C60017C1001626034F20271605AE0001F6
|
||||
:208220001F01C6001697C600164CC700164F9572FB01F690F7C60016A1082604725F001641
|
||||
:20824000A6015B0281521C5F1F031F017B21A1042303CC831D7B21A1032603CC831D0D21B4
|
||||
:208260002603CC831D961C00051F1B4F5F9772FB1B7F4CA10C25F51E1B1C000AA60AF77B98
|
||||
:2082800021A101270E7B21A102271C7B21A104272120301E1FF66B1A5F0F171F027B1A6B2D
|
||||
:2082A000047B176B01201C161F90FE5F17031F0120111E1FE6036B16E602FE6B031F017B5D
|
||||
:2082C000166B04A6096B114B0A5F894B001E07891E0789CD8B4E5B089F887B126B13840A41
|
||||
:2082E000115F417B124172FB1BAB30F74B0A5F894B001E07891E0789CD8C7F5B081F03174D
|
||||
:20830000011E0326041E0127067B11A1FF2CB87B114C5F9772FB1B89CD81EE5B025B1C8145
|
||||
:2083200052110F01965C5C1F101E101C000B7F1E16A300007B15A2007B14A2002E141616D1
|
||||
:2083400090504F1215974F12149517161F14A6016B01A60B6B0E4B0A5F894B001E1A891E22
|
||||
:208360001A89CD8AA95B089F0A0E5F417B0E4172FB10AB30F74B0A5F894B001E1A891E1A06
|
||||
:2083800089CD8BCB5B081F1617147B0EA1002C034F2002A6011E1626041E1427034D26B61A
|
||||
:2083A000887B0F6B10844D27140D0127100A0E7B0E6B0F5F7B0F9772FB10A62DF75F7B0F14
|
||||
:2083C0009772FB1089CD81EE5B025B1181521ACE00201F0DCE001E1F0B5F1F091F070F041E
|
||||
:2083E0000F020F01961C000389CD820E5B024D2603CC84717B03A12D260E1E09260A1E0731
|
||||
:208400002606A6016B0420697B03A1302403CC84937B03A1392303CC8493A6016B021E099C
|
||||
:20842000891E09894B0A5F894B00CD8D1E5B081F11170F7B030F195F90977B19909572F9FA
|
||||
:20844000119F1910979E190F9572A200309FA2006B149EA20017096B077B146B08AE7FFF4D
|
||||
:2084600013094F12084F120724075F1F091F070F0190CE002072F20DC6001F120C95C600DA
|
||||
:208480001E120B9790A327109EA2009FA2002403CC83E40D0126040D0226034F201A7B0948
|
||||
:2084A000887B0B6B07846B050D0427051E05501F051E1D1605FFA6015B1A81AE853889CDC1
|
||||
:2084C00081EE5B021E0389CD81EE5B024B0ACD81E084817B03A40F6B037B03887B04A10A36
|
||||
:2084E000842406AB306B032004AB576B037B0381AE854189CD81EE5B027B034EA40F88CD88
|
||||
:2085000084D35B0188CD81E0847B0388CD84D35B0188CD81E08481AE5011F6AA20F7AE5069
|
||||
:2085200012F6AA20F7AE5242A611F7AE5243A606F7AE5245A62CF7810A4552524F523A201F
|
||||
:04854000003078008F
|
||||
:028E87000000E9
|
||||
:20854400AE530CA604F7AE5011F6AA08F7AE5013F6AA08F7AE5306A668F7AE5305A602F75A
|
||||
:20856400AE5308A631F7AE5301A602F7AE5300A684F781725F001B3501000AAE530DA603F9
|
||||
:20858400F7AE530EA6E8F7AE5311A601F7AE5312A6F4F7AE5304A601F7AE5300F6AA01F7BC
|
||||
:2085A40035030018AE5300F64425F9CE0019A302262304A60120014F817B03C70009725F7E
|
||||
:2085C400001B3507000AAE530D7FAE530EA664F77200000902200CAE53117FAE5312A60A9C
|
||||
:2085E400F7200AAE53117FAE5312A63CF7AE5304A601F7725400097210530081725F000937
|
||||
:208604003501001B3508000AAE530D7FAE530EA664F7AE53117FAE5312A605F7AE5304A630
|
||||
:2086240001F772105300817B03C7001535020018CC86007B03C7001535010018815202AEC2
|
||||
:208644005300F6442403CC872AAE5010F6A5082603CC872AC60018A1012603CC86C7A10229
|
||||
:20866400270AA1032603CC871DCC872AAE87B289CD81EE5B023B0009CD84F0844B20CD8140
|
||||
:20868400E084C6001A88CD84F0844B0ACD81E084AE000B725A00159FCB0015979EA90095B2
|
||||
:2086A400C60009F7725D00152706CD8600CC872A725F0018CE001C2603CC872ACE001CFDAF
|
||||
:2086C400CC872AAE87BB89CD81EE5B02725D0015272FAE000B1F01C600154A5F9772FB016B
|
||||
:2086E400F688CD84F0844B0ACD81E084C600154AC70015974F9572FB01F688CD85BD842011
|
||||
:2087040025725F0018AE87C589CD81EE5B02CE001C2713CE001CFD200DAE87CE89CD81EE2B
|
||||
:208724005B02725F00185B02815210AE000B1F0F1E0FE604A1FF2603CC87AE1E0FE6079538
|
||||
:20874400160F90E6086B017B014EA40F6B0E9EA407484848481A0E979E4824049FAA80977A
|
||||
:208764009F494FA20095909790958990894BE84B035F89CD8D1E5B081F0C170A7B016B0919
|
||||
:208784000F085F7B09A40F90974F90954F974F959089894B7D5F894B00CD8D1E5B08517288
|
||||
:2087A400F90C9F190B979E190A95515B10817265636569766520007472616E736D6974202E
|
||||
:1787C400006973206F7665720A00726573657420646F6E65210A00C8
|
||||
:068E8900000000000000E3
|
||||
:208000008200808382000000820080A0820080A1820080A2820080A3820080A4820080A57E
|
||||
:20802000820080A6820080A78200000082000000820080A8820080A9820080AA820080AB3D
|
||||
:20804000820080AC82008155820081568200000082000000820081578200815882008159AC
|
||||
:20806000820081B7820081B8820081DF82000000820000008200000082000000820000001F
|
||||
:1D808300AE00152707724F00005A26F9AE000F2709D68E86D700155A26F7CC8080AF
|
||||
:03808000CC884960
|
||||
:2087DB005202AE000B1F01A608A1082E08884B2CCD81E084845F9772FB0188F69784888981
|
||||
:2087FB005B01CD84F084844AA1FF2CDD725F001D725F001CAE89EE89CD81EE5B02CD872D23
|
||||
:20881B00899089CD83205B04AE89F689CD81EE5B025B02814B09CD862B84AE87DBCF001C4E
|
||||
:20883B008135010024725F001D725F001C8152095F1F041F0272107F60AE50C67FAE5345FE
|
||||
:20885B00A607F7AE5346A67DF7AE5341A601F7AE5340A685F7AE500CF6AA04F7AE500DF60F
|
||||
:20887B00AA04F7CD8517CD85449ACE002072F0041F08C6001F12036B07C6001E1202CE00F2
|
||||
:20889B0022905F881309909F1208909E12015B012511CE00201304C6001F1203C6001E12F7
|
||||
:2088BB00022422CE00201F04CE001E1F02AE500AF6A804F7AE5010F6A5082609AE89FD89F9
|
||||
:2088DB00CD81EE5B02CD8641965C89CD820E5B024D2603CC89A87B01A12B2726A12D273EE0
|
||||
:2088FB00A1482712A168270EA172274AA1772603CC8981CC89A8AE8A1489CD81EE5B02CC2B
|
||||
:20891B0089A8CE00221C0064CF0022A327102203CC89A835F4002335010022CC89A8CE003F
|
||||
:20893B00221D0064CF0022A301F4246135F40023350100222057CD85774D2609AE8A5E89EC
|
||||
:20895B00CD81EE5B02AE8A6389CD81EE5B0290CE00195F908989CD83205B04AE8A8489CD4D
|
||||
:20897B0081EE5B022027CD85774D260BAE8A8789CD81EE5B022016AE000BA644F75CA6CC03
|
||||
:20899B00F7AE883CCF001C4B02CD863784725D00242603CC8885AE5010F6A5082603CC88EA
|
||||
:2089BB0085CD85774D271D725F0024AE882FCF001CAE000BA6BEF75CA6CCF74B02CD8637C8
|
||||
:2089DB0084CC8885AE8A9989CD81EE5B02CC88855B09810A54656D703A200064657267438F
|
||||
:2089FB000A00636F6E76657273696F6E20696E2070726F636573730A000A50524F544F3A14
|
||||
:208A1B000A2B2F2D094C454420706572696F640A532F73097365742F676574204D737065B1
|
||||
:208A3B0065640A723A20726573657420312D776972650A773A20726561642074656D706572
|
||||
:208A5B00720A006E6F742000666F756E6420312D77697265206465766963657320286563AA
|
||||
:208A7B00686F206C656E3A2000290A006E6F206465766963657320666F756E642100657204
|
||||
:0E8A9B00726F72207265736574696E672100D8
|
||||
:078E8F000000000001F400E7
|
||||
:208AA900521D1E22A300007B21A2007B20A2002F040F0D2004A6016B0D0D0D27151E225068
|
||||
:208AC9004F12216B1B4F12201F186B167B1B6B1720081622171816201716161817141616BD
|
||||
:208AE90017121E26A300007B25A2007B24A2002E1E7B27406B114F12266B104F12256B0F2E
|
||||
:208B09004F12246B0E1610170B160E170920081626170B16241709160B170716091E0789D6
|
||||
:208B290090891E18891E1889CD8B4E5B0817010D0D270D504F120290974F120190952002A3
|
||||
:208B490016015B1D8152040F020F017B0B484F494D262E160D1E0B905859170D1F0B1E097C
|
||||
:208B6900130D7B08120C7B07120B240D160D1E0B549056170D1F0B20080C017B016B022049
|
||||
:208B8900CA7B026B041E09130D7B08120C7B07120B2513160972F20D7B08120C977B0712FB
|
||||
:208BA9000B9517091F07160D1E0B549056170D1F0B7B046B030A040D0326CA1E0916075B58
|
||||
:208BC9000481521E1E23A300007B22A2007B21A2002F040F112004A6016B110D1127151E24
|
||||
:208BE90023504F12226B1C4F12211F146B127B1C6B13200816231714162117121614171962
|
||||
:208C0900161217171E27A300007B26A2007B25A2002F040F162004A6016B160D16271E7B01
|
||||
:208C290028406B104F12276B0F4F12266B0E4F12256B0D160F170B160D1709200816271742
|
||||
:208C49000B16251709160B170716091E078990891E1D891E1D89CD8C7F5B0817017B111801
|
||||
:208C6900164D270D504F120290974F12019095200216015B1E8152125F1F051F03A6206B86
|
||||
:208C8900027B15484F496B0116171E1590585917171F157B036B0F1E04887B076B138408BC
|
||||
:208CA9001259090F1F047B126B067B0F6B030D01271A7B06AA016B0A7B056B097B046B0839
|
||||
:208CC9007B036B0716091705160717031E05131B7B04121A7B031219252B160572F21B7B1F
|
||||
:208CE90004121A6B0C7B03121917056B037B0C6B047B18AA0190977B1790957B16977B15C7
|
||||
:208D09009517171F150A020D022703CC8C8A1E1716155B128152409096905C961C00431F26
|
||||
:208D2900051E05E603961C00471F0B1E0B1F0D1E0D1F3F1E3F88E60197844290FF72A90045
|
||||
:208D4900021E05E6031E0B1F071E071F091E091F0F1E0F88E60397844290FF965C1F151E3D
|
||||
:208D690015F66B171E05F697160B90E603429F1B171E15F71E15F66B1C1E05E60197160B64
|
||||
:208D890090E602429F1B1C1E15F79096905C93FE1F1D1E05E6011E0B1F231E231F251E25F4
|
||||
:208DA9001F271E2788E60397844272FB1D90FF93FE1F291E05E6021E0B1F2B1E2B1F2D1E2E
|
||||
:208DC9002D1F311E3188E60297844272FB2990FF16051E05E6021E0B1F331E331F351E3533
|
||||
:208DE9001F371E3788E6019784429F90F71E055C1F391E05E60290971E0BE60390421E3989
|
||||
:208E0900FF160B1E05E6031E0B1F3D1E3D1F2F1E2F88F69784429F90F71E0B5C1F3B1E059F
|
||||
:208E2900E60390971E0BE60290421E3BFF1E0B1C00037F1E051C00037F965CE6036B14E616
|
||||
:208E4900026B13E6016B12F616431718164572F9131721887B13191A6B218419186B1F166C
|
||||
:1E8E690021EF02161FFFE603E602FE16491E4772F9219F1920979E191F95515B40813F
|
||||
:00000001FF
|
||||
16
1-wire/tests
Normal file
16
1-wire/tests
Normal file
@ -0,0 +1,16 @@
|
||||
0x98,0x01,0x4b,0x46,0x7f,0xff,0x08,0x10,0x22
|
||||
|
||||
LSB: 10011000 = 152
|
||||
MSB: 00000001 = 1
|
||||
temperature = 11001 + 1/2 = 25.5
|
||||
|
||||
TH: 01001011 = 75
|
||||
TL: 01000110 = 70
|
||||
|
||||
conf: 01111111 = 127
|
||||
|
||||
res: 0xff - OK
|
||||
res: 1000 - 8
|
||||
res: 0x10 - OK
|
||||
|
||||
CRC: 100010 = 34
|
||||
169
1-wire/uart.c
Normal file
169
1-wire/uart.c
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* blinky.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 "ports_definition.h"
|
||||
#include "uart.h"
|
||||
#include "interrupts.h"
|
||||
|
||||
U8 UART_rx[UART_BUF_LEN]; // cycle buffer for received data
|
||||
U8 UART_rx_start_i = 0; // started index of received data (from which reading starts)
|
||||
U8 UART_rx_cur_i = 0; // index of current first byte in rx array (to which data will be written)
|
||||
|
||||
/**
|
||||
* Send one byte through UART
|
||||
* @param byte - data to send
|
||||
*/
|
||||
void UART_send_byte(U8 byte){
|
||||
while(!(UART2_SR & UART_SR_TXE)); // wait until previous byte transmitted
|
||||
UART2_DR = byte;
|
||||
}
|
||||
|
||||
void uart_write(char *str){
|
||||
while(*str){
|
||||
while(!(UART2_SR & UART_SR_TXE));
|
||||
UART2_CR2 |= UART_CR2_TEN;
|
||||
UART2_DR = *str++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read one byte from Rx buffer
|
||||
* @param byte - where to store readed data
|
||||
* @return 1 in case of non-empty buffer
|
||||
*/
|
||||
U8 UART_read_byte(U8 *byte){
|
||||
if(UART_rx_start_i == UART_rx_cur_i) // buffer is empty
|
||||
return 0;
|
||||
*byte = UART_rx[UART_rx_start_i++];
|
||||
check_UART_pointer(UART_rx_start_i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void printUint(U8 *val, U8 len){
|
||||
unsigned long Number = 0;
|
||||
U8 i = len;
|
||||
char ch;
|
||||
U8 decimal_buff[12]; // max len of U32 == 10 + \n + \0
|
||||
if(len > 4 || len == 3 || len == 0) return;
|
||||
for(i = 0; i < 12; i++)
|
||||
decimal_buff[i] = 0;
|
||||
decimal_buff[10] = '\n';
|
||||
ch = 9;
|
||||
switch(len){
|
||||
case 1:
|
||||
Number = *((U8*)val);
|
||||
break;
|
||||
case 2:
|
||||
Number = *((U16*)val);
|
||||
break;
|
||||
case 4:
|
||||
Number = *((unsigned long*)val);
|
||||
break;
|
||||
}
|
||||
do{
|
||||
i = Number % 10L;
|
||||
decimal_buff[ch--] = i + '0';
|
||||
Number /= 10L;
|
||||
}while(Number && ch > -1);
|
||||
uart_write((char*)&decimal_buff[ch+1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* print signed long onto terminal
|
||||
* max len = 10 symbols + 1 for "-" + 1 for '\n' + 1 for 0 = 13
|
||||
*/
|
||||
void print_long(long Number){
|
||||
U8 i, L = 0;
|
||||
char ch;
|
||||
char decimal_buff[12];
|
||||
decimal_buff[11] = 0;
|
||||
ch = 11;
|
||||
if(Number < 0){
|
||||
Number = -Number;
|
||||
L = 1;
|
||||
}
|
||||
do{
|
||||
i = Number % 10L;
|
||||
decimal_buff[--ch] = i + '0';
|
||||
Number /= 10L;
|
||||
}while(Number && ch > 0);
|
||||
if(ch > 0 && L) decimal_buff[--ch] = '-';
|
||||
uart_write(&decimal_buff[ch]);
|
||||
}
|
||||
|
||||
U8 readInt(int *val){
|
||||
unsigned long T = Global_time;
|
||||
unsigned long R = 0;
|
||||
int readed;
|
||||
U8 sign = 0, rb, ret = 0, bad = 0;
|
||||
do{
|
||||
if(!UART_read_byte(&rb)) continue;
|
||||
if(rb == '-' && R == 0){ // negative number
|
||||
sign = 1;
|
||||
continue;
|
||||
}
|
||||
if(rb < '0' || rb > '9') break; // number ends with any non-digit symbol that will be omitted
|
||||
ret = 1; // there's at least one digit
|
||||
R = R * 10L + rb - '0';
|
||||
if(R > 0x7fff){ // bad value
|
||||
R = 0;
|
||||
bad = 0;
|
||||
}
|
||||
}while(Global_time - T < 10000); // wait no longer than 10s
|
||||
if(bad || !ret) return 0;
|
||||
readed = (int) R;
|
||||
if(sign) readed *= -1;
|
||||
*val = readed;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void error_msg(char *msg){
|
||||
uart_write("\nERROR: ");
|
||||
uart_write(msg);
|
||||
UART_send_byte('\n');
|
||||
}
|
||||
|
||||
U8 U8toHEX(U8 val){
|
||||
val &= 0x0f;
|
||||
if(val < 10) val += '0';
|
||||
else val += 'a' - 10;
|
||||
return val;
|
||||
}
|
||||
|
||||
void printUHEX(U8 val){
|
||||
uart_write("0x");
|
||||
UART_send_byte(U8toHEX(val>>4)); // MSB
|
||||
UART_send_byte(U8toHEX(val)); // LSB
|
||||
}
|
||||
|
||||
void uart_init(){
|
||||
// PD5 - UART2_TX
|
||||
PORT(UART_PORT, DDR) |= UART_TX_PIN;
|
||||
PORT(UART_PORT, CR1) |= UART_TX_PIN;
|
||||
// Configure UART
|
||||
// 8 bit, no parity, 1 stop (UART_CR1/3 = 0 - reset value)
|
||||
// 57600 on 16MHz: BRR1=0x11, BRR2=0x06
|
||||
UART2_BRR1 = 0x11; UART2_BRR2 = 0x06;
|
||||
UART2_CR2 = UART_CR2_TEN | UART_CR2_REN | UART_CR2_RIEN; // Allow RX/TX, generate ints on rx
|
||||
}
|
||||
|
||||
|
||||
45
1-wire/uart.h
Normal file
45
1-wire/uart.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* blinky.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 __MAIN_H__
|
||||
#define __MAIN_H__
|
||||
|
||||
extern volatile unsigned long Global_time; // global time in ms
|
||||
|
||||
#define UART_BUF_LEN 8 // max 7 bytes transmited in on operation
|
||||
|
||||
extern U8 UART_rx[];
|
||||
extern U8 UART_rx_start_i;
|
||||
extern U8 UART_rx_cur_i;
|
||||
|
||||
|
||||
void UART_send_byte(U8 byte);
|
||||
void uart_write(char *str);
|
||||
void printUint(U8 *val, U8 len);
|
||||
void print_long(long Number);
|
||||
void error_msg(char *msg);
|
||||
void uart_init();
|
||||
U8 UART_read_byte(U8 *byte);
|
||||
void printUHEX(U8 val);
|
||||
|
||||
#define check_UART_pointer(x) do{if(x == UART_BUF_LEN) x = 0;}while(0)
|
||||
|
||||
#endif // __MAIN_H__
|
||||
34
voltmeters/src/3-digit/Makefile
Normal file
34
voltmeters/src/3-digit/Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
NAME=testproj
|
||||
SDCC=sdcc
|
||||
|
||||
CCFLAGS=-DSTM8S003 -I../ -I/usr/share/sdcc/include -mstm8 --out-fmt-ihx
|
||||
LDFLAGS=-mstm8 --out-fmt-ihx -lstm8
|
||||
FLASHFLAGS=-cstlinkv2 -pstm8s003
|
||||
|
||||
SRC=$(wildcard *.c)
|
||||
# ATTENTION: FIRST in list should be file with main()
|
||||
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
|
||||
156
voltmeters/src/3-digit/interrupts.c
Normal file
156
voltmeters/src/3-digit/interrupts.c
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
U8 ADC_ready = 0; // flag: data ready
|
||||
int ADC_value = 0;// value of last ADC measurement
|
||||
|
||||
// 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){
|
||||
ADC_value = ADC_DRL; // in right-alignment mode we should first read LSB
|
||||
ADC_value |= ADC_DRH << 8;
|
||||
ADC_ready = 1;
|
||||
ADC_CSR &= 0x3f; // clear EOC & AWD flags
|
||||
}
|
||||
#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){}
|
||||
148
voltmeters/src/3-digit/interrupts.h
Normal file
148
voltmeters/src/3-digit/interrupts.h
Normal 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__
|
||||
241
voltmeters/src/3-digit/led.c
Normal file
241
voltmeters/src/3-digit/led.c
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* 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
|
||||
* **
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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};
|
||||
// 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
|
||||
|
||||
/**
|
||||
* 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;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on anode power for digit N (0..3: PA3, PD6, PD4, PD1 -- A0x08, D0x40, D0x10, D0x02)
|
||||
* @param N - number of digit (0..3), if other - no action (display off)
|
||||
* @return
|
||||
*/
|
||||
void light_up_digit(U8 N){
|
||||
switch(N){
|
||||
case 0:
|
||||
PA_ODR |= 0x08;
|
||||
break;
|
||||
case 1:
|
||||
PD_ODR |= 0x40;
|
||||
break;
|
||||
case 2:
|
||||
PD_ODR |= 0x10;
|
||||
break;
|
||||
case 3:
|
||||
PD_ODR |= 0x02;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static U8 display_buffer[4] = {' ',' ',' ',' '}; // 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, -999 <= i <= 9999, 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 < -999 || I > 9999){
|
||||
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[3] = 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;
|
||||
}
|
||||
43
voltmeters/src/3-digit/led.h
Normal file
43
voltmeters/src/3-digit/led.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
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
|
||||
* PA1|3, PB4|5, PC3|4|5|6|7, PD1|4|6
|
||||
*/
|
||||
#define LED_init() do{ \
|
||||
PA_DDR = 0x0a; PB_DDR = 0x30; PC_DDR = 0xf8; PD_DDR = 0x52; \
|
||||
PA_CR1 = 0x0a; PB_CR1 = 0x30; PC_CR1 = 0xf8; PD_CR1 = 0x52; \
|
||||
}while(0)
|
||||
|
||||
#endif // __LED_H__
|
||||
164
voltmeters/src/3-digit/main.c
Normal file
164
voltmeters/src/3-digit/main.c
Normal file
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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
|
||||
//eeprom_data *saved_data = (eeprom_data*)EEPROM_START_ADDR;
|
||||
|
||||
//U32 testtimer;
|
||||
|
||||
// one digit emitting time
|
||||
#define LED_delay 1
|
||||
/*
|
||||
U8 change_eeprom_value(U8 *addr, U8 *val, U8 len){
|
||||
U8 i;
|
||||
// unlock memory
|
||||
FLASH_DUKR = EEPROM_KEY1;
|
||||
FLASH_DUKR = EEPROM_KEY2;
|
||||
// check bit DUL=1 in FLASH_IAPSR
|
||||
if(!(FLASH_IAPSR & 0x08))
|
||||
return 0;
|
||||
for(i = 0; i < len; i++)
|
||||
*addr = val[i];
|
||||
while(!(FLASH_IAPSR & 0x04)); // wait till end
|
||||
// clear DUL to lock write
|
||||
FLASH_IAPSR &= ~0x08;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void eeprom_default_setup(){
|
||||
eeprom_data template = {
|
||||
.magick = EEPROM_MAGICK,
|
||||
.ADU_to_mV = DEFAULT_ADU_TO_MV,
|
||||
.max_ADU = DEFAULT_MAX_ADU
|
||||
};
|
||||
if(saved_data->magick != EEPROM_MAGICK){
|
||||
if(change_eeprom_value((U8*)saved_data, (U8*)&template, sizeof(eeprom_data)))
|
||||
testtimer = saved_data->ADU_to_mV;
|
||||
else
|
||||
testtimer = 999;
|
||||
}else{
|
||||
testtimer = 0; // other times - from zero
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
int main() {
|
||||
U32 T_LED = 0L; // time of last digit update
|
||||
U32 T_time = 0L; // timer
|
||||
int U = 0;
|
||||
U8 vcap = 0; // ADC selection: 1 - vcap, 0 - ain
|
||||
int pidx = 0; // index in median buffer
|
||||
long voltagein = 0L, voltagecap = 0L; // variables for average values: vin and vcap
|
||||
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;
|
||||
//eeprom_default_setup();
|
||||
// configure ADC
|
||||
// select PD3[AIN4] - AIN .. PD6[AIN6] - Vcap & enable interrupt for EOC
|
||||
ADC_CSR = 0x24; // 0x24 - AIN4, 0x26 - AIN6
|
||||
ADC_TDRL = 0x50; // disable Schmitt triger for AIN4 & AIN6
|
||||
// right alignment
|
||||
ADC_CR2 = 0x08; // don't forget: first read ADC_DRL!
|
||||
// f_{ADC} = f/18 & continuous non-buffered conversion & wake it up
|
||||
ADC_CR1 = 0x73; // 0x71 - single, 0x73 - continuous
|
||||
ADC_CR1 = 0x73; // turn on ADC (this needs second write operation)
|
||||
|
||||
// enable all interrupts
|
||||
enableInterrupts();
|
||||
set_display_buf(" E0 "); // low power -> infinitive rebooting
|
||||
// Loop
|
||||
do {
|
||||
// onse per 300ms refresh displayed value
|
||||
if(((unsigned int)(Global_time - T_time) > 300) || (T_time > Global_time)){
|
||||
T_time = Global_time;
|
||||
voltagein /= cntrin; // average
|
||||
voltagecap /= cntrcap;
|
||||
// voltage = 1800 * ADUin / ADUcap
|
||||
voltagein *= 1800;
|
||||
U = (int)(voltagein/voltagecap);
|
||||
display_int(U, 1);
|
||||
cntrin = 0;
|
||||
cntrcap = 0;
|
||||
voltagein = 0L;
|
||||
voltagecap = 0L;
|
||||
pidx = 0;
|
||||
}
|
||||
if((U8)(Global_time - T_LED) > LED_delay){
|
||||
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;
|
||||
}
|
||||
T_LED = Global_time;
|
||||
show_next_digit();
|
||||
}
|
||||
} while(1);
|
||||
}
|
||||
|
||||
40
voltmeters/src/3-digit/main.h
Normal file
40
voltmeters/src/3-digit/main.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 EEPROM_MAGICK (0x1234)
|
||||
#define DEFAULT_ADU_TO_MV (35840)
|
||||
#define DEFAULT_MAX_ADU (119800)
|
||||
|
||||
typedef struct{
|
||||
U16 magick;
|
||||
U32 ADU_to_mV;
|
||||
U32 max_ADU;
|
||||
}eeprom_data;
|
||||
*/
|
||||
#define CONCAT(a,b) a##_##b
|
||||
#define PORT(a,b) CONCAT(a,b)
|
||||
|
||||
#endif // __MAIN_H__
|
||||
106
voltmeters/src/3-digit/testproj.ihx
Normal file
106
voltmeters/src/3-digit/testproj.ihx
Normal file
@ -0,0 +1,106 @@
|
||||
:2080A000808080808080808080AE5255F644241B90CE001A72A90001C60019A90097C600F9
|
||||
:2080C00018A9009590CF001ACF0018AE52557F80808080808080AE5405F65F97CF0016AE10
|
||||
:2080E0005404F65F9758585858585858589FCA0017979ECA001695CF001635010015AE5420
|
||||
:0881000000F6A43FF780808027
|
||||
:038C380000000039
|
||||
:208000008200808382000000820080A0820080A1820080A2820080A3820080A4820080A57E
|
||||
:20802000820080A6820080A78200000082000000820080A8820080A9820080D0820080D1F1
|
||||
:20804000820080D28200000082000000820080D3820080D4820080D58200000082000000C2
|
||||
:20806000820080D6820081068200810782000000820000008200000082000000820000008B
|
||||
:1D808300AE00142707724F00005A26F9AE00422709D68C37D700145A26F7CC8080CF
|
||||
:03808000CC83634B
|
||||
:208108005238AE00031F051E055C5C1F011E01FE160572A900041703160390FE171D131D81
|
||||
:208128002D0FCF00011E01161DFF1E0390CE0001FF1E051C00081F1B1E1BFE160572A9006D
|
||||
:208148000A1723162390FE172113212D0FCF00011E1B1621FF1E2390CE0001FF1E051C0047
|
||||
:208168000E1F1F1E1FFE160572A900101719161990FE171713172D0FCF00011E1F1617FF70
|
||||
:208188001E1990CE0001FF1E05FE160190FE171513152D0FCF00011E051615FF1E0190CE52
|
||||
:2081A8000001FF1E051C00061F131E13FE161B90FE171113112D0FCF00011E131611FF1E85
|
||||
:2081C8001B90CE0001FF1E051C000C1F0F1E0FFE161F90FE170D130D2D0FCF00011E0F1624
|
||||
:2081E8000DFF1E1F90CE0001FF1E01FE160390FE170B130B2D0FCF00011E01160BFF1E0360
|
||||
:2082080090CE0001FF1E1BFE162390FE170913092D0FCF00011E1B1609FF1E2390CE0001BB
|
||||
:20822800FF1E1FFE161990FE170713072D0FCF00011E1F1607FF1E1990CE0001FF1E05FEEC
|
||||
:20824800161390FE173713372D0FCF00011E051637FF1E1390CE0001FF1E23FE161990FEC1
|
||||
:20826800173513352D0FCF00011E231635FF1E1990CE0001FF1E1BFE161F90FE17331333AC
|
||||
:208288002D0FCF00011E1B1633FF1E1F90CE0001FF1E13FE160F90FE173113312D0FCF0035
|
||||
:2082A800011E131631FF1E0F90CE0001FF1E01FE161B90FE172F132F2D0FCF00011E01160E
|
||||
:2082C8002FFF1E1B90CE0001FF1E03FE162390FE172D132D2D0FCF00011E03162DFF1E23B7
|
||||
:2082E80090CE0001FF1E1BFE161F90FE172B132B2D0FCF00011E1B162BFF1E1F90CE00017D
|
||||
:20830800FF1E1BFE160390FE172913292D0FCF00011E1B1629FF1E0390CE0001FF1E0FFECF
|
||||
:20832800161B90FE172713272D0FCF00011E0F1627FF1E1B90CE0001FF1E1BFE160390FE14
|
||||
:20834800172513252D0FCF00011E1B1625FF1E0390CE0001FF1E1BFE5B388152425F1F1A2C
|
||||
:208368001F185F1F161F140F135F1F115F1F221F205F1F3D1F3B5F1F031F015F1F071F0508
|
||||
:20838800AE50C67F72107F60AE5002A60AF7AE5007A630F7AE500CA6F8F7AE5011A652F71B
|
||||
:2083A800AE5003A60AF7AE5008A630F7AE500DA6F8F7AE5012A652F7AE7F0AF6AA28F7AEF7
|
||||
:2083C80052607FAE5261A60FF7AE5262A603F7AE5263A6E8F7AE5254A601F7AE5250A68500
|
||||
:2083E800F7AE5400A624F7AE5407A650F7AE5402A608F7AE5401A673F7AE5401A673F79A5C
|
||||
:20840800AE858989CD866B5B02CE001A72F016C6001912156B25C600181214A3012C2211F7
|
||||
:20842800CE001A1316C600191215C6001812142476CE001A1F16CE00181F141E03891E037E
|
||||
:20844800891E26891E2689CD88E95B081F0F170D1E07891E07891E41891E4189CD88E95B39
|
||||
:20846800081F0B17091E0F891E0F894B084B075F89CD8A7A5B081F321E0B891E0B891E366C
|
||||
:20848800899089CD88E95B084B0189CD87EB5B035F1F031F015F1F071F055F1F221F205F97
|
||||
:2084A8001F3D1F3B5F1F11C6001B887B1C6B39841038A1012203CC8411725D00152603CCFE
|
||||
:2084C8008576AE00031F391E115872FB3990CE0016FF1E115C1F111E11A300092703CC85DF
|
||||
:2084E800720D132740CD81089E494FA2006B3572FB3D887B36193D6B4184193B1F3D6B3BEE
|
||||
:208508007B406B3C1E071C00017B06A9006B2D7B05A9001F076B057B2D6B06AE5400A62449
|
||||
:20852800F70F132042CD81089F905F5D2A02905A9772FB22909F19216B29909E19201F2296
|
||||
:208548006B207B296B211E031C00017B02A9006B1D7B01A9001F036B017B1D6B02AE5400B2
|
||||
:20856800A626F7A6016B135F1F11725F0015CE001A1F1ACE00181F18CD87BDCC84115B4249
|
||||
:06858800812045302000B7
|
||||
:048C3B000000000035
|
||||
:20858E0052047B07A47F6B01AE500FF6A4CFF7AE5000F6A4F7F7AE5005F6A4CFF7AE500A08
|
||||
:2085AE00F6A407F7AE500FF6A4FDF7AE5005F66B047B01A1122444AE001C9F1B01979EA918
|
||||
:2085CE000095F61A04AE5005F7AE500AF66B03AE002E9F1B01979EA90095F61A03AE500A59
|
||||
:2085EE00F7AE500FF66B02AE00409F1B01979EA90095F61A02AE500FF720167B04AA30AE97
|
||||
:20860E005005F7AE500AF6AAF8F7AE500FF6AA02F77B07482407AE500AF6A4BFF75B048196
|
||||
:20862E007B03A10027147B03A10127177B03A102271A7B03A103271D2022AE5000F6AA08C4
|
||||
:20864E00F72019AE500FF6AA40F72010AE500FF6AA10F72007AE500FF6AA02F781521272F0
|
||||
:20866E005F0056AE00521F0C4F5F9772FB0C88A620F7844CA1032FF11E152603CC879B9695
|
||||
:20868E001C00041F070F01161517091E09F66B03887B024A6B0C844D2603CC876F7B01A101
|
||||
:2086AE00032F03CC876F4F957B03A12F2D0C7B03A13A2E06A63095CC87547B03A1602C04FC
|
||||
:2086CE000F122004A6016B127B03A1672F034F2002A60114124D2706A65795CC87547B03FC
|
||||
:2086EE00A1402C040F112004A6016B117B03A1472F034F2002A60114114D2705A637952014
|
||||
:20870E00457B03A12D2605A61D95203A7B03A1682605A65795202F7B03A1482605A6379546
|
||||
:20872E0020247B03A12E26180D0126071E07A6FFF720265F7B0B9772FB07F6AA80F72019DA
|
||||
:20874E007B03A1202613905F7B01909772F9077B038910018590F70C011E095C1F09CC8661
|
||||
:20876E00997B0B6B027B026B10A6026B037B10A1FF2D1A5F7B039772FB0C1F0E5F7B109744
|
||||
:20878E0072FB07F61E0EF70A100A0320E05B12817B03A1022218AE00529F1B03979EA90033
|
||||
:2087AE0095F688CD858E847B0388CD862E8481C6005695725C00569E88CD879E84C600561B
|
||||
:2087CE00A1022304725F005681725D00562706C600564A2002A60288CD862E848152090F1F
|
||||
:2087EE00010F021E0CA3FC192F071E0CA3270F2D0CAE88E589CD866B5B02CC88CD0D0E27E3
|
||||
:20880E002CAE00521F064F5F9772FB067F4CA1032FF51E0CA303E72D294B0A4B001E0E894C
|
||||
:20882E00CD8BE35B041F0CA6016B012015AE00521F044F5F9772FB0488A620F7844CA1038B
|
||||
:20884E002FF11E0C2607AE00557FCC88CD1E0CA300002E09A6016B021E0C501F0CAE005233
|
||||
:20886E001F08A6026B034B0A4B001E0E89CD8A3C5B04905F7B03909772F9089F90F74B0AE4
|
||||
:20888E004B001E0E89CD8BE35B041F0C0A037B03A1FF2C034F2002A6014D27041E0C26C605
|
||||
:2088AE000D02270D4D270A5F7B039772FB08A610F70D0E270A5F7B019772FB087999765B3D
|
||||
:1B88CE0009817B03A102220EAE00529F1B03979EA90095799976812D2D4500DC
|
||||
:208C3F0000101010002020100000002020102020302080B80010381000B0001020088008B5
|
||||
:1B8C5F00002038280000020000000000000000000200020202002020202000F0
|
||||
:2088E900521E1E23A300007B22A2007B21A2002F040F112004A6016B110D1127151E235019
|
||||
:208909004F12226B1C4F12211F146B127B1C6B13200816231714162117121614171916128F
|
||||
:2089290017171E27A300007B26A2007B25A2002F040F162004A6016B160D16271E7B2840A4
|
||||
:208949006B104F12276B0F4F12266B0E4F12256B0D160F170B160D170920081627170B166C
|
||||
:20896900251709160B170716091E078990891E1D891E1D89CD899D5B0817017B1118164D87
|
||||
:20898900270D504F120290974F12019095200216015B1E8152125F1F051F03A6206B027B4F
|
||||
:2089A90015484F496B0116171E1590585917171F157B036B0F1E04887B076B1384081259B1
|
||||
:2089C900090F1F047B126B067B0F6B030D01271A7B06AA016B0A7B056B097B046B087B0309
|
||||
:2089E9006B0716091705160717031E05131B7B04121A7B031219252B160572F21B7B04126A
|
||||
:208A09001A6B0C7B03121917056B037B0C6B047B18AA0190977B1790957B16977B15951713
|
||||
:208A2900171F150A020D022703CC89A81E1716155B128152051E08A300002F040F012004CB
|
||||
:208A4900A6016B010D0127051E085020021E081F041E0AA300002E071E0A501F022004160C
|
||||
:208A69000A170216021E0465930D012701505B058152409096905C961C00431F051E05E66B
|
||||
:208A890003961C00471F0B1E0B1F0D1E0D1F3F1E3F88E60197844290FF72A900021E05E6EB
|
||||
:208AA900031E0B1F071E071F091E091F0F1E0F88E60397844290FF965C1F151E15F66B175E
|
||||
:208AC9001E05F697160B90E603429F1B171E15F71E15F66B1C1E05E60197160B90E60242DA
|
||||
:208AE9009F1B1C1E15F79096905C93FE1F1D1E05E6011E0B1F231E231F251E251F271E27C6
|
||||
:208B090088E60397844272FB1D90FF93FE1F291E05E6021E0B1F2B1E2B1F2D1E2D1F311EC0
|
||||
:208B29003188E60297844272FB2990FF16051E05E6021E0B1F331E331F351E351F371E37C5
|
||||
:208B490088E6019784429F90F71E055C1F391E05E60290971E0BE60390421E39FF160B1E98
|
||||
:208B690005E6031E0B1F3D1E3D1F2F1E2F88F69784429F90F71E0B5C1F3B1E05E603909770
|
||||
:208B89001E0BE60290421E3BFF1E0B1C00037F1E051C00037F965CE6036B14E6026B13E663
|
||||
:208BA900016B12F616431718164572F9131721887B13191A6B218419186B1F1621EF02164D
|
||||
:208BC9001FFFE603E602FE16491E4772F9219F1920979E191F95515B408152081E0BA300E2
|
||||
:208BE900002F040F052004A6016B050D0527051E0B5020021E0B1F011E0DA300002F040FB8
|
||||
:208C0900062004A6016B060D0627107B0E406B044F120D6B03160317072004160D170716F9
|
||||
:0F8C2900071E01657B0518064D2701505B08816A
|
||||
:00000001FF
|
||||
@ -1,31 +1,29 @@
|
||||
NAME=testproj
|
||||
SDCC=sdcc
|
||||
HEX2BIN=hex2bin
|
||||
|
||||
CCFLAGS=-DSTM8S003 -I../ -I/usr/share/sdcc/include -mstm8 --out-fmt-ihx
|
||||
LDFLAGS= -lstm8 -mstm8 --out-fmt-ihx
|
||||
LDFLAGS=-mstm8 --out-fmt-ihx -lstm8
|
||||
FLASHFLAGS=-cstlinkv2 -pstm8s003
|
||||
|
||||
SRC=$(wildcard *.c)
|
||||
# ATTENTION: FIRST in list should be file with main()
|
||||
OBJ=$(SRC:%.c=%.rel)
|
||||
TRASH=$(OBJ) $(SRC:%.c=%.rst) $(SRC:%.c=%.asm) $(SRC:%.c=%.lst)
|
||||
TRASH+=$(SRC:%.c=%.sym) $(NAME).ihx $(NAME).lk $(NAME).map
|
||||
TRASH+=$(SRC:%.c=%.sym) $(NAME).lk $(NAME).map
|
||||
INDEPENDENT_HEADERS=../stm8l.h Makefile
|
||||
|
||||
all: $(NAME).bin
|
||||
all: $(NAME).ihx
|
||||
|
||||
$(SRC) : %.c : %.h $(INDEPENDENT_HEADERS)
|
||||
@touch $@
|
||||
@echo $@
|
||||
|
||||
%.h: ;
|
||||
|
||||
clean:
|
||||
rm -f $(TRASH)
|
||||
|
||||
load: $(NAME).bin
|
||||
stm8flash $(FLASHFLAGS) -w $(NAME).bin
|
||||
load: $(NAME).ihx
|
||||
stm8flash $(FLASHFLAGS) -w $(NAME).ihx
|
||||
|
||||
%.rel: %.c
|
||||
$(SDCC) $(CCFLAGS) -c $<
|
||||
@ -33,7 +31,4 @@ load: $(NAME).bin
|
||||
$(NAME).ihx: $(OBJ)
|
||||
$(SDCC) $(LDFLAGS) $(OBJ) -o $(NAME).ihx
|
||||
|
||||
$(NAME).bin: $(NAME).ihx
|
||||
$(HEX2BIN) -p 00 $<
|
||||
|
||||
.PHONY: all
|
||||
|
||||
@ -205,10 +205,10 @@ void display_int(int I, char voltmeter){
|
||||
// prepare buffer for voltmeter's values
|
||||
if(voltmeter){
|
||||
for(i = 1; i < 4; i++)
|
||||
display_buffer[i] = ' ';
|
||||
display_buffer[i] = 0;
|
||||
}else{
|
||||
for(i = 1; i < 4; i++)
|
||||
display_buffer[i] = 0;
|
||||
display_buffer[i] = ' ';
|
||||
}
|
||||
if(I == 0){ // just show zero
|
||||
display_buffer[3] = 0;
|
||||
|
||||
@ -1,31 +1,29 @@
|
||||
NAME=testproj
|
||||
SDCC=sdcc
|
||||
HEX2BIN=hex2bin
|
||||
|
||||
CCFLAGS=-DSTM8S003 -I../ -I/usr/share/sdcc/include -mstm8 --out-fmt-ihx
|
||||
LDFLAGS= -lstm8 -mstm8 --out-fmt-ihx
|
||||
LDFLAGS=-mstm8 --out-fmt-ihx -lstm8
|
||||
FLASHFLAGS=-cstlinkv2 -pstm8s003
|
||||
|
||||
SRC=$(wildcard *.c)
|
||||
# ATTENTION: FIRST in list should be file with main()
|
||||
OBJ=$(SRC:%.c=%.rel)
|
||||
TRASH=$(OBJ) $(SRC:%.c=%.rst) $(SRC:%.c=%.asm) $(SRC:%.c=%.lst)
|
||||
TRASH+=$(SRC:%.c=%.sym) $(NAME).ihx $(NAME).lk $(NAME).map
|
||||
TRASH+=$(SRC:%.c=%.sym) $(NAME).lk $(NAME).map
|
||||
INDEPENDENT_HEADERS=../stm8l.h Makefile
|
||||
|
||||
all: $(NAME).bin
|
||||
all: $(NAME).ihx
|
||||
|
||||
$(SRC) : %.c : %.h $(INDEPENDENT_HEADERS)
|
||||
@touch $@
|
||||
@echo $@
|
||||
|
||||
%.h: ;
|
||||
|
||||
clean:
|
||||
rm -f $(TRASH)
|
||||
|
||||
load: $(NAME).bin
|
||||
stm8flash $(FLASHFLAGS) -w $(NAME).bin
|
||||
load: $(NAME).ihx
|
||||
stm8flash $(FLASHFLAGS) -w $(NAME).ihx
|
||||
|
||||
%.rel: %.c
|
||||
$(SDCC) $(CCFLAGS) -c $<
|
||||
@ -33,7 +31,4 @@ load: $(NAME).bin
|
||||
$(NAME).ihx: $(OBJ)
|
||||
$(SDCC) $(LDFLAGS) $(OBJ) -o $(NAME).ihx
|
||||
|
||||
$(NAME).bin: $(NAME).ihx
|
||||
$(HEX2BIN) -p 00 $<
|
||||
|
||||
.PHONY: all
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user