add LEDS_BT

This commit is contained in:
eddyem
2019-12-17 21:49:29 +03:00
parent 897a2f1cbf
commit 0425dc8981
20 changed files with 1624 additions and 866 deletions

3
LEDS_BT/LEDs.config Normal file
View File

@@ -0,0 +1,3 @@
// Add predefined macros for your project here. For example:
// #define THE_ANSWER 42
#define STM8S103

1
LEDS_BT/LEDs.creator Normal file
View File

@@ -0,0 +1 @@
[General]

6
LEDS_BT/LEDs.files Normal file
View File

@@ -0,0 +1,6 @@
interrupts.c
interrupts.h
main.c
ports_definition.h
uart.c
uart.h

1
LEDS_BT/LEDs.includes Normal file
View File

@@ -0,0 +1 @@
../

34
LEDS_BT/Makefile Normal file
View File

@@ -0,0 +1,34 @@
NAME=uart
SDCC=sdcc
CCFLAGS=-DSTM8S103 -I../ -I/usr/share/sdcc/include -mstm8 --out-fmt-ihx
LDFLAGS= -mstm8 --out-fmt-ihx -lstm8
FLASHFLAGS=-cstlinkv2 -pstm8s103f2
SRC=$(wildcard *.c)
OBJ=$(SRC:%.c=%.rel)
TRASH=$(OBJ) $(SRC:%.c=%.rst) $(SRC:%.c=%.asm) $(SRC:%.c=%.lst) $(SRC:%.c=%.cdb)
TRASH+=$(SRC:%.c=%.sym) $(NAME).lk $(NAME).map
INDEPENDENT_HEADERS=../stm8s.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

2
LEDS_BT/Readme Normal file
View File

@@ -0,0 +1,2 @@
Setup "bluetooth control 8-lamp", connect STM8S103F2 to bluetooth HC-06.
Manage up to 8 LEDs controlled by bluetooth module HC-06

167
LEDS_BT/interrupts.c Normal file
View File

@@ -0,0 +1,167 @@
/*
* interrupts.c
*
* Copyright 2018 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"
// 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 flag
}
// 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
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){
U8 rb;
unsigned long Tlast = 0;
if(UART1_SR & UART_SR_RXNE){ // data received
rb = UART1_DR; // read received byte & clear RXNE flag
if(uart_ready) return; // omit everything before command read
if(Global_time - Tlast < CMD_PAUSE){ // need a little pause
Tlast = Global_time;
return;
}
Tlast = Global_time;
//if(rb == '+') return; // answer when disconnected
UART_rx_cmd = rb; // put received byte into cycled buffer
uart_ready = 1;
}
}
#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
INTERRUPT_HANDLER(ADC1_IRQHandler, 22){ // read ADC value
}
#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){}

147
LEDS_BT/interrupts.h Normal file
View File

@@ -0,0 +1,147 @@
/*
* 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 "stm8s.h"
extern volatile U8 ADC_ready; // flag: data ready
extern volatile 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__

141
LEDS_BT/main.c Normal file
View File

@@ -0,0 +1,141 @@
/*
* 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"
volatile unsigned long Global_time = 0L; // global time in ms
/*
LED channels:
0 - D3
1 - D2
2 - D1
3 - C7
4 - C6
5 - C5
6 - C4
7 - C3
*/
/* don't work!
static U8* LEDODRS[8] = {(U8*)0x500F, &PD_ODR, &PD_ODR, &PC_ODR, &PC_ODR, &PC_ODR, &PC_ODR, &PC_ODR};
static const U8 LEDPINS[8] = {1<<3, 1<<2, 1<<1, 1<<7, 1<<6, 1<<5, 1<<4, 1<<3};
*/
int main() {
unsigned long T = 0L;
U8 rb;
CFG_GCR |= 1; // disable SWIM
// Configure clocking
CLK_CKDIVR = 0; // F_HSI = 16MHz, f_CPU = 16MHz
// TIM1 - system timer (1ms)
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;
// leds - opendrain
PD_DDR = 0x0e;
PC_DDR = 0xf8;
/*
PD_CR1 = 0x0e;
PC_CR1 = 0xf8;
*/
PORT(LED_PORT, DDR) |= LED_PIN;
PORT(LED_PORT, CR1) |= LED_PIN;
uart_init();
// enable all interrupts
enableInterrupts();
// Loop
do{
if(Global_time - T > 499){
T = Global_time;
PORT(LED_PORT, ODR) ^= LED_PIN; // blink on-board LED
}
if(uart_read_cmd(&rb)){ // buffer isn't empty
switch(rb){
case '1':
PD_ODR |= (1<<3);
break;
case '2':
PD_ODR |= (1<<2);
break;
case '3':
PD_ODR |= (1<<1);
break;
case '4':
PC_ODR |= (1<<7);
break;
case '5':
PC_ODR |= (1<<6);
break;
case '6':
PC_ODR |= (1<<5);
break;
case '7':
PC_ODR |= (1<<4);
break;
case '8':
PC_ODR |= (1<<3);
break;
case 'A':
PD_ODR &= (1<<3);
break;
case 'B':
PD_ODR &= (1<<2);
break;
case 'C':
PD_ODR &= (1<<1);
break;
case 'D':
PC_ODR &= (1<<7);
break;
case 'E':
PC_ODR &= (1<<6);
break;
case 'F':
PC_ODR &= (1<<5);
break;
case 'G':
PC_ODR &= (1<<4);
break;
case 'H':
PC_ODR &= (1<<3);
break;
case '9':
PD_ODR |= 0x0e;
PC_ODR |= 0xf8;
break;
case 'I':
PD_ODR &= ~0x0e;
PC_ODR &= ~0xf8;
break;
}
}
}while(1);
}

View File

@@ -0,0 +1,43 @@
/*
* 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 "stm8s.h"
// minimal pause between commands (ms)
#define CMD_PAUSE 100
// 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 - PB5
#define LED_PORT PB
#define LED_PIN GPIO_PIN5
// UART2_TX
#define UART_PORT PD
#define UART_TX_PIN GPIO_PIN5
#endif // __PORTS_DEFINITION_H__

67
LEDS_BT/uart.c Normal file
View File

@@ -0,0 +1,67 @@
/*
* blinky.c
*
* Copyright 2018 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_cmd; // command received
volatile U8 uart_ready = 0;// command ready flag
/**
* Send one byte through UART
* @param byte - data to send
*/
void uart_send_byte(U8 byte){
while(!(UART1_SR & UART_SR_TXE)); // wait until previous byte transmitted
UART1_DR = byte;
}
void uart_write(char *str){
while(*str){
while(!(UART1_SR & UART_SR_TXE));
UART1_CR2 |= UART_CR2_TEN;
UART1_DR = *str++;
}
}
/**
* Read one byte from Rx buffer
* @param byte - where to store data read
* @return 1 in case of non-empty buffer
*/
U8 uart_read_cmd(U8 *byte){
if(!uart_ready) // buffer is empty
return 0;
*byte = UART_rx_cmd;
uart_ready = 0;
return 1;
}
void uart_init(){
// PD5 - UART1_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)
// 9600 on 16MHz: DIV=0x0693 -> BRR1=0x68, BRR2=0x03
UART1_BRR1 = 0x68; UART1_BRR2 = 0x03;
UART1_CR2 = UART_CR2_TEN | UART_CR2_REN | UART_CR2_RIEN; // Allow RX/TX, generate ints on rx
}

46
LEDS_BT/uart.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* blinky.h
*
* Copyright 2018 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 "stm8s.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_cmd;
extern volatile U8 uart_ready;
void uart_send_byte(U8 byte);
void uart_write(char *str);
void newline();
void printUint(U8 *val, U8 len);
void print_long(long Number);
void error_msg(char *msg);
void uart_init();
U8 uart_read_cmd(U8 *byte);
void printUHEX(U8 val);
#define check_UART_pointer(x) do{if(x == UART_BUF_LEN) x = 0;}while(0)
#endif // __MAIN_H__

30
LEDS_BT/uart.ihx Normal file
View File

@@ -0,0 +1,30 @@
:20809100808080808080808080C6525544241BCE00051C0001C60004A9009097C60003A963
:2080B100009095CF000590CF000335005255808080808088C65230A5202741C652316B0146
:2080D100725D0002263690CE0005CE000390A300649FA2009EA200240EC60006C60005C687
:2080F1000004C600032015C60006C60005C60004C600037B01C700013501000284808080C3
:0281110080806C
:20811300C652302AFBAE52317B03F7811E03F6260181C652302AFB72165235F65CC75231E1
:2081330020EC81725D000226024F811E03C60001F7725F0002A60181721A5011721A501221
:0D8153003568523235035233352C523581D8
:01808C0000F3
:208000008200806F82000000820080918200809282008093820080948200809582008096EC
:2080200082008097820080988200000082000000820080998200809A820080C0820080C14D
:20804000820080C28200000082000000820080C3820080C48200810F8200000082000000B7
:0C806000820081108200811182008112D8
:1D806F00AE00012707724F00005A26F9AE00052709D6808BD700015A26F7CC806C12
:03806C00CC816064
:2081600052095F1F081F06C67F60905FAA01C77F60350050C635005260350F526135035261
:208180006235E852633501525435855250350E501135F8500C721A5007C65008AA20C75064
:2081A00008CD814B9ACE000572F0081F04C6000412076B03C6000312066B02AE01F31304CC
:2081C0004F12034F12022412CE00051F08CE00031F06C65005A820C75005965C89CD8136B4
:2081E0005B024D27C07B01A13125BA7B01A14922B47B01A0315F9758DE81FCFC822E82352C
:20820000823C8243824A82518258825F82BE81A581A581A581A581A581A581A5826682715C
:20822000827C82878292829D82A882B382D37216500FCC81A57214500FCC81A57212500FBD
:20824000CC81A5721E500ACC81A5721C500ACC81A5721A500ACC81A57218500ACC81A57256
:2082600016500ACC81A5C6500FA408C7500FCC81A5C6500FA404C7500FCC81A5C6500FA405
:2082800002C7500FCC81A5C6500AA480C7500ACC81A5C6500AA440C7500ACC81A5C6500A36
:2082A000A420C7500ACC81A5C6500AA410C7500ACC81A5C6500AA408C7500ACC81A5C6500B
:2082C0000FAA0EC7500FC6500A905FAAF8C7500ACC81A5C6500FA4F1C7500FC6500AA40742
:0682E000C7500ACC81A585
:04808D0000000000EF
:00000001FF