Код содержит работу таймера с прерывание раз в секунду, измерение АЦП прием передача по уарт и прерывание на ножке

код
Код:
/*
**
** Main.c
**
**
**********************************************************************/
/*
Last committed: $Revision: 00 $
Last changed by: $Author: $
Last changed date: $Date: $
ID: $Id: $

**********************************************************************/
#include "stm32f10x_conf.h"
#include "string.h"
//#include "stm32f10x_rcc.h"
//#include "stm32f10x_exti.h"
//#include "stm32f10x_spi.h"
//#include "stm32f10x_usart.h"
//#include "stm32f10x_gpio.h"
//#include "misc.h"

#define led_off GPIO_SetBits(GPIOA, GPIO_Pin_1)
#define led_on GPIO_ResetBits(GPIOA, GPIO_Pin_1)

#define set_cs GPIO_SetBits(GPIOB, GPIO_Pin_0)
#define reset_cs GPIO_ResetBits(GPIOB, GPIO_Pin_0)

#define set_res GPIO_SetBits(GPIOB, GPIO_Pin_1)
#define reset_res GPIO_ResetBits(GPIOB, GPIO_Pin_1)

#define set_rs GPIO_SetBits(GPIOB, GPIO_Pin_2)
#define reset_rs GPIO_ResetBits(GPIOB, GPIO_Pin_2)


#define Whiblu = 0xH7FF

#define Red 0xF800
#define Green 0x07E0
#define Blue 0x001F
#define White 0xFFFF
#define Black 0x0000
#define Yellow 0xFFE0
#define Cyan 0x0410
#define Magenta 0x8010
#define Brown 0xFC00
#define Olive 0x8400
#define Bright_red 0xF800
#define Bright_green 0x07E0
#define Bright_blue 0x001F
#define Bright_yellow 0xFFE0
#define Bright_cyan 0x07FF
#define Bright_magenta 0xF81F
#define Light_gray 0x8410
#define Dark_gray 0x4208
#define Light_blue 0x841F
#define Light_green 0x87F0
#define Light_cyan 0x87FF
#define Light_red 0xFC10
#define Gray1 0xC618
#define Gray2 0xA514
#define Gray3 0x630C
#define Gray4 0x4208
#define Gray5 0x2104
#define Gray6 0x3186
#define Blue0 0x1086
#define Blue1 0x3188
#define Blue2 0x4314
#define Blue3 0x861C
#define Cyan0 0x3D34
#define Cyan1 0x1DF7
#define Green0 0x0200
#define Green1 0x0208


uint8_t ini_code[82]={0xCB, 0x39, 0x2C, 0x00, 0x34, 0x02, 0xCF, 0x00, 0x81, 0x30,
0xE8, 0x84, 0x11, 0x7A, 0xEA, 0x00, 0x00, 0xED, 0x64, 0x03, 0x12, 0x81,
0xF7, 0x20, 0xC0, 0x23, 0xC1, 0x10, 0xC5, 0x3E, 0x28, 0xC7, 0x86,
0x36, 0x08, 0x3A, 0x55, 0xB1, 0x00, 0x18, 0xB6, 0x08, 0x82, 0x27,
0xF2, 0x00, 0x26, 0x01, 0xE0, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08,
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, 0xE1, 0x00,
0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C,
0x31, 0x36, 0x0F, 0x11, 0x29};


uint8_t bukvi[960]={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x03, 0x00,
0x03, 0x00, 0x00, 0x24, 0x7e, 0x24, 0x7e, 0x24, 0x00, 0x26, 0x49, 0x7f, 0x49, 0x32, 0x00, 0x22,
0x10, 0x08, 0x04, 0x22, 0x00, 0x30, 0x4a, 0x45, 0x4a, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x41, 0x3e, 0x00, 0x00, 0x2a, 0x1c, 0x3e,
0x1c, 0x2a, 0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,
0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00, 0x00, 0x04, 0x02, 0x7f, 0x00, 0x00, 0x42, 0x61, 0x51,
0x49, 0x46, 0x00, 0x22, 0x41, 0x49, 0x49, 0x36, 0x00, 0x07, 0x08, 0x08, 0x08, 0x7f, 0x00, 0x2f,
0x49, 0x49, 0x49, 0x31, 0x00, 0x3e, 0x49, 0x49, 0x49, 0x32, 0x00, 0x01, 0x01, 0x71, 0x09, 0x07,
0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x26, 0x49, 0x49, 0x49, 0x3e, 0x00, 0x00, 0x00, 0x24,
0x00, 0x00, 0x00, 0x00, 0x80, 0x64, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x14,
0x14, 0x14, 0x14, 0x14, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x00, 0x02, 0x01, 0x51, 0x09, 0x06,
0x00, 0x3e, 0x41, 0x4d, 0x49, 0x26, 0x00, 0x7c, 0x12, 0x11, 0x12, 0x7c, 0x00, 0x7f, 0x49, 0x49,
0x49, 0x36, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7f, 0x41, 0x41, 0x41, 0x3e, 0x00, 0x7f,
0x49, 0x49, 0x49, 0x41, 0x00, 0x7f, 0x09, 0x09, 0x01, 0x01, 0x00, 0x3e, 0x41, 0x59, 0x49, 0x3a,
0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x20, 0x40, 0x40,
0x40, 0x3f, 0x00, 0x7f, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7f, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7f,
0x02, 0x04, 0x02, 0x7f, 0x00, 0x7f, 0x04, 0x08, 0x10, 0x7f, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e,
0x00, 0x7f, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3e, 0x41, 0x51, 0x61, 0x7e, 0x00, 0x7f, 0x09, 0x19,
0x29, 0x46, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x00, 0x3f,
0x40, 0x40, 0x40, 0x3f, 0x00, 0x0f, 0x30, 0x40, 0x30, 0x0f, 0x00, 0x3f, 0x40, 0x3f, 0x40, 0x3f,
0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x61, 0x51, 0x49,
0x45, 0x43, 0x00, 0x00, 0x00, 0x7f, 0x41, 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00,
0x00, 0x41, 0x7f, 0x00, 0x00, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x30, 0x4a, 0x4a, 0x2a, 0x7c, 0x00, 0x3f, 0x44, 0x44,
0x44, 0x38, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x24, 0x00, 0x38, 0x44, 0x44, 0x24, 0x7f, 0x00, 0x3c,
0x4a, 0x4a, 0x4a, 0x2c, 0x00, 0x00, 0x04, 0x7e, 0x05, 0x00, 0x00, 0x1c, 0xa2, 0xa2, 0xa2, 0x7c,
0x00, 0x7f, 0x04, 0x04, 0x04, 0x78, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80,
0x80, 0x7a, 0x00, 0x7f, 0x10, 0x08, 0x14, 0x62, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x7e,
0x02, 0x7c, 0x02, 0x7c, 0x00, 0x7e, 0x02, 0x02, 0x02, 0x7c, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x3c,
0x00, 0xfe, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x3c, 0x42, 0x42, 0x22, 0xfe, 0x00, 0x7e, 0x04, 0x02,
0x02, 0x04, 0x00, 0x24, 0x4a, 0x4a, 0x4a, 0x30, 0x00, 0x00, 0x02, 0x3f, 0x42, 0x40, 0x00, 0x3e,
0x40, 0x40, 0x20, 0x7e, 0x00, 0x0e, 0x30, 0x40, 0x30, 0x0e, 0x00, 0x3e, 0x40, 0x3e, 0x40, 0x3e,
0x00, 0x62, 0x14, 0x08, 0x14, 0x62, 0x00, 0x1e, 0xa0, 0xa0, 0xa0, 0x7e, 0x00, 0x62, 0x52, 0x4a,
0x46, 0x42, 0x00, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00,
0x41, 0x36, 0x08, 0x00, 0x00, 0x00, 0x08, 0x04, 0x08, 0x04, 0x00, 0x78, 0x48, 0x48, 0x78, 0x00,
0x00, 0x7c, 0x12, 0x11, 0x12, 0x7c, 0x00, 0x7f, 0x45, 0x45, 0x45, 0x39, 0x00, 0x7f, 0x49, 0x49,
0x49, 0x36, 0x00, 0x7f, 0x01, 0x01, 0x01, 0x01, 0x00, 0xc0, 0x7e, 0x41, 0x7e, 0xc0, 0x00, 0x7f,
0x49, 0x49, 0x49, 0x41, 0x00, 0x77, 0x08, 0x7f, 0x08, 0x77, 0x00, 0x41, 0x41, 0x49, 0x49, 0x36,
0x00, 0x7f, 0x10, 0x08, 0x04, 0x7f, 0x00, 0x7f, 0x10, 0x09, 0x04, 0x7f, 0x00, 0x7f, 0x08, 0x14,
0x22, 0x41, 0x00, 0x78, 0x04, 0x02, 0x01, 0x7f, 0x00, 0x7f, 0x02, 0x04, 0x02, 0x7f, 0x00, 0x7f,
0x08, 0x08, 0x08, 0x7f, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00, 0x7f, 0x01, 0x01, 0x01, 0x7f,
0x00, 0x7f, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x22, 0x00, 0x01, 0x01, 0x7f,
0x01, 0x01, 0x00, 0x07, 0x48, 0x48, 0x48, 0x3f, 0x00, 0x0e, 0x11, 0x7f, 0x11, 0x0e, 0x00, 0x63,
0x14, 0x08, 0x14, 0x63, 0x00, 0x7f, 0x40, 0x40, 0x40, 0xff, 0x00, 0x07, 0x08, 0x08, 0x08, 0x7f,
0x00, 0x7f, 0x40, 0x7e, 0x40, 0x7f, 0x00, 0x7f, 0x40, 0x7e, 0x40, 0xff, 0x00, 0x01, 0x7f, 0x44,
0x44, 0x38, 0x00, 0x7f, 0x44, 0x38, 0x00, 0x7f, 0x00, 0x7f, 0x44, 0x44, 0x44, 0x38, 0x00, 0x41,
0x41, 0x49, 0x49, 0x3e, 0x00, 0x7f, 0x08, 0x3e, 0x41, 0x3e, 0x00, 0x66, 0x19, 0x09, 0x09, 0x7f,
0x00, 0x30, 0x4a, 0x4a, 0x2a, 0x7c, 0x00, 0x34, 0x4a, 0x4a, 0x4a, 0x32, 0x00, 0x3c, 0x4a, 0x4a,
0x4a, 0x34, 0x00, 0x7c, 0x02, 0x02, 0x02, 0x02, 0x00, 0xc0, 0x7c, 0x42, 0x7e, 0xc0, 0x00, 0x3c,
0x4a, 0x4a, 0x4a, 0x2c, 0x00, 0x76, 0x08, 0x7e, 0x08, 0x76, 0x00, 0x24, 0x42, 0x4a, 0x4a, 0x34,
0x00, 0x3e, 0x40, 0x40, 0x20, 0x7e, 0x00, 0x3e, 0x40, 0x41, 0x20, 0x7e, 0x00, 0x7e, 0x08, 0x08,
0x14, 0x62, 0x00, 0x78, 0x04, 0x02, 0x02, 0x7e, 0x00, 0x7e, 0x04, 0x08, 0x04, 0x7e, 0x00, 0x7e,
0x08, 0x08, 0x08, 0x7e, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x7e, 0x04, 0x02, 0x02, 0x7c,
0x00, 0xfe, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x24, 0x00, 0x02, 0x02, 0x7e,
0x02, 0x02, 0x00, 0x9e, 0xa0, 0xa0, 0xa0, 0x7e, 0x00, 0x3c, 0x42, 0xfe, 0x42, 0x3c, 0x00, 0x62,
0x14, 0x08, 0x14, 0x62, 0x00, 0x3e, 0x40, 0x40, 0x40, 0xbe, 0x00, 0x0e, 0x10, 0x10, 0x10, 0x7e,
0x00, 0x7e, 0x40, 0x7c, 0x40, 0x7e, 0x00, 0x7e, 0x40, 0x7c, 0x40, 0xfe, 0x00, 0x02, 0x7e, 0x48,
0x48, 0x30, 0x00, 0x7e, 0x48, 0x30, 0x00, 0x7e, 0x00, 0x7e, 0x48, 0x48, 0x48, 0x30, 0x00, 0x42,
0x42, 0x4a, 0x4a, 0x3c, 0x00, 0x7e, 0x08, 0x3c, 0x42, 0x3c, 0x00, 0x4c, 0x32, 0x12, 0x12, 0x7e};

unsigned char Temp;
unsigned char n;
unsigned int n1;
unsigned int n2;
unsigned int n3;
unsigned int f;
unsigned char i;
unsigned char bb;
unsigned int iii;
char text1[25];
char text2[25];
unsigned char zh;
unsigned char zz;
unsigned char dlina;
unsigned int xend;
unsigned int yend;
unsigned char flag_uart;
unsigned char b23;
unsigned char asd;
unsigned int aaa=0;
unsigned char sec1;
unsigned char sec2;
double ggg;


int main(void)
{

//GPIO_InitTypeDef PORT;
GPIO_InitTypeDef GPIO_InitStructure; //работа с портами
SPI_InitTypeDef SPI_InitStructure; // работа с SPI
USART_InitTypeDef USART_InitStructure; // работа с UART
EXTI_InitTypeDef EXTI_InitStructure; // внешние прерывания
NVIC_InitTypeDef NVIC_InitStructure; // контроллер прерываний
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
ADC_InitTypeDef ADC_InitStructure;
//TIM_OCInitTypeDef TIM_OCInitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_SPI1, ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/*============================ НАСТРОЙКА UART =======================================*/


USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);

//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

/* Configure USART1 Rx (PA10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure USART1 Tx (PA9) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
NVIC_EnableIRQ (USART2_IRQn);
USART2->CR1 |= USART_CR1_RXNEIE; //Прерывание по приему

/*============================ ================== НАСТРОЙКА SPI=======================================*/


GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
GPIO_Init(GPIOB, &GPIO_InitStructure);

//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
//GPIO_Init(GPIOB, &GPIO_InitStructure);

 

/* Configure SPI1 pins: SCK and MOSI ---------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

SPI_I2S_DeInit(SPI1);

/* SPI1 Configure */
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
//SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

/* Starting SPI */
SPI_Init(SPI1, &SPI_InitStructure);
SPI_Cmd(SPI1, ENABLE);

//======================================НАСТРОЙКА ПРЕРЫВАНИЯ НА ПОРТУ В9=====================================================

GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9); // выбор порта на котором хотим получить внешнее прерывание
//EXTI_DeInit();
EXTI_InitStructure.EXTI_Line = EXTI_Line9;// выбираем линию порта
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;// настраиваем на внешнее прерывание
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);


//далее идут настройки приоритета прерываний.
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

 

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOB, &GPIO_InitStructure);

//AFIO->EXTICR[3]|=AFIO_EXTICR3_EXTI9_PB;
//EXTI->IMR|=(EXTI_IMR_MR9);
//EXTI->FTSR|=(EXTI_FTSR_TR9);
//====================================== ПРЕРЫВАНИЕ ПО ТАЙМЕРУ =====================================================
TIM_TimeBaseInitTypeDef tim;
TIM_TimeBaseStructInit(&tim);
tim.TIM_Prescaler = 30000-1; //делитель
tim.TIM_Period = 2400; // период через которое происходит переполнение таймера, у нас он равен 150.
//каждые 150 тиков счетчика у нас будет срабатывать прерывание по переполнению.
TIM_TimeBaseInit(TIM2, &tim);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); // включаем прерывание по переполнению счетчика таймера
TIM_Cmd(TIM2, ENABLE);// включаем таймер
NVIC_EnableIRQ(TIM2_IRQn); // разрешаем прерывание от таймера


//======================================================================================

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// define ADC config
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // we work in continuous sampling mode
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 0;

ADC_RegularChannelConfig(ADC1,ADC_Channel_1, 0,ADC_SampleTime_28Cycles5); // define regular conversion config
ADC_Init ( ADC1, &ADC_InitStructure); //set config of ADC1

// enable ADC
ADC_Cmd (ADC1,ENABLE); //enable ADC1

// ADC calibration (optional, but recommended at power on)
ADC_ResetCalibration(ADC1); // Reset previous calibration
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1); // Start new calibration (ADC must be off at that time)
while(ADC_GetCalibrationStatus(ADC1));

// start conversion
ADC_Cmd (ADC1,ENABLE); //enable ADC1
ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start conversion (wil

 


//led_off;
init_lcd();
clear_screen(Black);
//clear_screen(Red);
//String_print(50,50,"5",White,Black,8,8);
//String_print(50,50,"6",White,Black,15,15);
//pset(200,200,Green);
//Circle(100,100,50,Red);
//String_print(50,50,"A",White,Black,8,8);
//clear_screen(Yellow);
//clear_screen(Blue);
//clear_screen(Magenta);


NVIC_EnableIRQ(EXTI9_5_IRQn);//разрешаем прерывание

while(1)
{

if (flag_uart==50){
led_on;
//text1=text2;
String_print(10,10,text2,White,Black,2,2);

asd=0;
sprintf(text1, "%d\n", Temp);
print(text1);

memset(text2, 0, sizeof(text2)); //Очищаем буфер
//sprintf(text1, "%d\n", Temp);
//print(text1);
flag_uart=0;
//delay_ms(500);
//led_off;
}


if (aaa==50){
led_on;
Temp++;
sprintf(text1, "%d", Temp);
//text1=123;
String_print(50,50,text1,White,Black,8,8);
delay_ms(500);
led_off;
aaa=0;
}

}
}
//=============================================================================================================
void spi_Dat8(unsigned char dat)
{
SPI_I2S_SendData(SPI1, dat);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
//SPI_I2S_SendData(SPI1, 0x00);
//while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
}
//=============================================================================================================
void spi_Dat16(unsigned int dat)
{
SPI_I2S_SendData(SPI1, dat>>8);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, dat);
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
}
//=============================================================================================================
void delay_ms(uint32_t ms)
{
volatile uint32_t nCount;
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq (&RCC_Clocks);

nCount=(RCC_Clocks.HCLK_Frequency/10000)*ms;
for (; nCount!=0; nCount--);
}
//=============================================================================================================
void delay_us(uint32_t ms)
{
volatile uint32_t nCount;
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq (&RCC_Clocks);

nCount=(RCC_Clocks.HCLK_Frequency/1000000)*ms;
for (; nCount!=0; nCount--);
}
//=============================================================================================================
void init_lcd()
{
set_cs;
set_res;
delay_ms(500);
reset_res;
delay_ms(500);
set_res;
delay_ms(50);

for (Temp=0; Temp<82; Temp++){
n=ini_code[Temp];
if (Temp==0||Temp==6||Temp==10||Temp==14||Temp==17||Temp==22||Temp==24||Temp==28||Temp==31||Temp==33||Temp==35||Temp==37||Temp==40||Temp==44||Temp==48||Temp==64||Temp > 79){
command_send_8(n);
}
else{
data_send_8(n);
}
if (Temp==5) {
delay_ms(50);
}
}
delay_ms(100);
}
//=============================================================================================================
void command_send_8(unsigned char dat)
{
reset_rs;
reset_cs;
//delay_ms(1);
spi_Dat8(dat);
//delay_ms(1);
set_cs;
}
//=============================================================================================================
void data_send_8(unsigned char dat)
{
set_rs;
reset_cs;
//delay_ms(1);
spi_Dat8(dat);
//delay_ms(1);
set_cs;
}
//=============================================================================================================
void data_send(unsigned int dat)
{
set_rs;
reset_cs;
//delay_ms(1);
spi_Dat16(dat);
//delay_ms(1);
set_cs;
}
//=============================================================================================================
void Window_locate(unsigned int x,unsigned int y,unsigned int x_end,unsigned int y_end)
{
command_send_8(0x2A);
data_send(x);
data_send(x_end);

command_send_8(0x2B);
data_send(y);
data_send(y_end);

command_send_8(0x2C);
}

void clear_screen(unsigned int dat1)
{
Window_locate(0,0,239,319);
set_rs;
reset_cs;
//delay_ms(1);
for (f=1;f<19201;f++){
spi_Dat16(dat1);
spi_Dat16(dat1);
spi_Dat16(dat1);
spi_Dat16(dat1);
}
//delay_ms(1);
set_cs;

}

void String_print(unsigned int x,unsigned int y,char *lcd_text,unsigned int color,unsigned int fon,unsigned char uvel,unsigned char szatie)
{

dlina=strlen(lcd_text);

yend=szatie*6*dlina+y-1;
xend=uvel*8+x-1;
i=0;
Window_locate(x,y,xend,yend);
set_rs;
reset_cs;
while(lcd_text[i]){
n1=lcd_text[i];
n1=n1-32;
if (n1>159){
n1=n1-64;
}
n1=n1*6;

for (n3=n1;n3<n1+6;n3++){

n=bukvi[n3];
zz=0;

while(zz!=szatie){

for(bb=0;bb<8;bb++){

zh=0;

while(zh!=uvel){

if (((n >> bb) & 1)==1){
spi_Dat16(color);
}
else{
spi_Dat16(fon);
}

zh++;
}

}

zz++;
}

}

i++;
}

set_cs;
}


void pset(unsigned int x,unsigned int y,unsigned int color){
Window_locate(x,y,x,y);
set_rs;
reset_cs;
spi_Dat16(color);
set_cs;
}

void Circle (unsigned int x, unsigned int y, unsigned char rad, unsigned int color)
{
signed int tswitch, x1=0, y1;
char d;

d = y - x;
y1 = rad;
tswitch = 3 - 2 * rad;
while (x1 <= y1)
{
pset(x + x1, y + y1, color);
pset(x + x1, y - y1, color);
pset(x - x1, y + y1, color);
pset(x- x1, y - y1, color);
pset(y + y1 - d, y + x1, color);
pset(y + y1 - d, y - x1, color);
pset(y - y1 - d, y+ x1, color);
pset(y - y1 - d, y - x1, color);

if (tswitch < 0) tswitch += (4 * x1 + 6);
else
{
tswitch += (4 * (x1 - y1) + 10);
y1--;
}
x1++;
}
}

void print(const char* str)
{
//USART_SendData(USART2,0x0A);
for(iii = 0; str[iii]; iii++){
while(!USART_GetFlagStatus(USART2,USART_FLAG_TC));
USART_SendData(USART2,str[iii]);
}
//++;
//str="\n";

}

void EXTI9_5_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line9);

if (EXTI_GetITStatus(EXTI_Line9) != RESET)
{
aaa=50;
}
}

// ************************************************************************************************************
void USART2_IRQHandler (void)
{
if (USART2->SR & USART_SR_RXNE) //Проверяем, прило ли чтонибудь в UART
{
b23=USART2->DR;

if (b23>31){
text2[asd]=b23;
asd++;
}

if (b23=='\r')
{
flag_uart=50;
//led_on;
}
}
}

void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
sec1++;
if (((sec1 >> 0) & 1)==1){
led_on;
}
if (((sec1 >> 0) & 1)==0){
led_off;
}

unsigned long j = ADC_GetConversionValue(ADC1);
j=j*806/100000;
//sprintf(text1, "%0.1d", j);
//strcat(text1," V ");
//ggg=j*0.000806;
//ggg=1.2;
sprintf(text1, "%d V ",j);
String_print(100,100,text1,White,Black,2,2);

}
}

Отредактировано SyncMVGP (2016-04-06 12:21:24)