Commit 11dd1c88 authored by wang.yulin's avatar wang.yulin

陈炎锋调试样机版本初次上传,作代码备份/追溯

parents
Pipeline #309 failed with stages
/* ----------------------------------------------------------------------
* Copyright (C) 2010 ARM Limited. All rights reserved.
*
* $Date: 11. November 2010
* $Revision: V1.0.2
*
* Project: CMSIS DSP Library
* Title: arm_common_tables.h
*
* Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions
*
* Target Processor: Cortex-M4/Cortex-M3
*
* Version 1.0.2 2010/11/11
* Documentation updated.
*
* Version 1.0.1 2010/10/05
* Production release and review comments incorporated.
*
* Version 1.0.0 2010/09/20
* Production release and review comments incorporated.
* -------------------------------------------------------------------- */
#ifndef _ARM_COMMON_TABLES_H
#define _ARM_COMMON_TABLES_H
#include "arm_math.h"
extern uint16_t armBitRevTable[256];
extern q15_t armRecipTableQ15[64];
extern q31_t armRecipTableQ31[64];
extern const q31_t realCoefAQ31[1024];
extern const q31_t realCoefBQ31[1024];
#endif /* ARM_COMMON_TABLES_H */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef _DELAY_H__
#define _DELAY_H__
#define u8 unsigned char
#define u16 unsigned int
void delay_msnvic(u16 time);
void delay_usnvic(u16 time);
void delay_us(unsigned int a);
void MX_TIM3_Init(void);
#endif
#ifndef _FLASH_
#define _FLASH_
#include "stm32f0xx.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "common.h"
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
//typedef uint32_t u32;
//typedef uint16_t u16;
//typedef uint8_t u8;
typedef __IO uint32_t vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t vu8;
//#include "stm32f10x.h"
/* BootLoader Flash首地址 */
#define SYS_Bootloader_SAVE_ADDR_BASE 0x08000000//Bootloader首地址
/* 升级参数存储 */
#define UPDATE_PARAM_SAVE_ADDR_BASE 0x08002C00
#define UPDATE_PARAM_MAX_SIZE (1*1024)//支持参数大小1KB
/* APP Flash首地址 */
#define SYS_APP_SAVE_ADDR_BASE 0x08010000
#define APP_DATA_MAX_SIZE (64*1024)//支持APP大小26KB
/* APP BAK Flash首地址 */
#define SYS_APP_BAK_SAVE_ADDR_BASE 0x08020000
#define APP_BAK_DATA_MAX_SIZE (64*1024)//支持APP_BAK大小26KB
/* FLASH页大小 */
//#define FLASH_PAGE_SIZE 0x400U //1KB
#define PIECE_MAX_LEN 256
#define SAVE_ADDR_BASE 0x08003C00 //15K
#define NEED_UPDATA_PARAM 0xA5A5 //////10100101 10100101
#define DONT_UPDATA_PARAM 0x5A5A //////01011010 01011010
//FLASH起始地址
#define STM32_FLASH_BASE 0x08000000 //STM32 FLASH的起始地址
#define FLASH_WAITETIME 50000 //FLASH等待超时时间
void save_param_to_flash(uint16_t * buf_to_save,uint16_t len );
void read_param_from_flash(uint16_t * buf_to_get,uint16_t len);
void set_flash_flag_to_updata(uint16_t crc_code);
void flash_erase(uint32_t size , uint32_t addr_base);
void EraseFlash(uint32_t size);
void rFlashData(uint8_t * buf_to_get , uint16_t len , uint32_t rFlashAddr);
void wFlashData(uint8_t * buf_to_save , uint16_t len , uint32_t wFlashAddr);
void iap_load_app(u32 appxaddr);
void FLASH_EEPROM_Write(uint32_t n,uint32_t add);
uint32_t FLASH_EEPROM_Read(uint32_t add);
u32 STMFLASH_ReadWord(u32 faddr);
void Test_Write(u32 WriteAddr,u32 WriteData);
void STMFLASH_Write(u32 WriteAddr,u32 *pBuffer,u32 NumToWrite);
#endif
/**
******************************************************************************
* File Name : gpio.h
* Description : This file contains all the functions prototypes for
* the gpio
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __gpio_H
#define __gpio_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_it.h"
#include "stm32f0xx.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
void O_GPIO_Init(void);
//void O_GPIO_Init();
void I_GPIO_Init(void);
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ pinoutConfig_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#ifndef _HT16C23_H__
#define _HT16C23_H__
//#include "stm8s_gpio.h"
#define u8 unsigned char
void init_ht16c23(void);
void I2CWriteSingle(char I2CData,char I2CData_sub);
void ht16c23_write_one_byte2ram(u8 addr ,u8 data);
void ht16c23_write_bytes2ram(u8 addr ,u8 *data, u8 len);
void ht16c23_write_val(u8 com,u8 seg, u8 seg_val);
void ht16c23_clear(void);
u8 ht16c23_read_one_byte2ram(u8 addr);
#endif
#ifndef __KEY_H
#define __KEY_H
#include "stm32f0xx.h"
#define u8 unsigned char
#define u16 unsigned int
#define KEY1 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5)//ȡ1
#define KEY2 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_6)//ȡ2
#define KEY3 GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_7)//ȡ3
#define KEY4 GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5)//ȡ4
#define KEY1_PRES 1 //KEY1
#define KEY2_PRES 2 //KEY2
#define KEY3_PRES 3 //KEY3
#define KEY4_PRES 4 //KEY4
//void KEY_Init(void);//IOʼ
extern u8 KEY_Scan(void); //ɨ躯
void KEY_Init(void);
void keyHandle(void);
#endif
#ifndef _LED_H
#define _LED_H
#include "stm32f0xx.h"
#include "stm32f0xx_dma.h"
#include <stdio.h>
#include <string.h>
void LEDHandle(void);
void LEDInit(void);
#define TURNLED1() GPIOB->ODR ^= GPIO_Pin_1
#define TURNLED2() GPIOB->ODR ^= GPIO_Pin_3
#define TURNLED3() GPIOB->ODR ^= GPIO_Pin_4
#endif
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx.h"
#include "stm32f0xx_it.h"
#include "usart.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
#define PAGE0 0
#define PAGE1 1
#define PAGE2 2
#define PAGE3 3
#define PAGE4 4
#define PAGE5 5
#define PAGE6 6
#define PAGE7 7
#define PAGE8 8
#define PAGE9 9
#define PAGE10 10
#define PAGE11 11
#define PAGE12 12
#define PAGE13 13
#define PAGE14 14
#define PAGE15 15
#define PAGE16 16
#define V 0
#define KV 1
#define A 2
#define KA 3
#define KW 5
#define MV 6
#define VA 7
#define KVA 8
#define MVA 9
#define C 10
#define PERCENT 11
#define MA 12
#define HZ 13
#define KVAR 14
#define MVAR 15
#define BOUND2400 1
#define BOUND9600 2
#define BOUND19200 3
#define BOUND115200 4
#define ADDR 1
#define BOUND 2
#define CT 3
#define PT 4
#define CTNUM_TWO 2
#define CTNUM_THREE 3
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
extern const unsigned char Play1_5_1[];
extern const u8 Play1_5_spec1[];
extern const u8 Play1_5_spec2[];
extern DataStructure DataStruc;
extern void ExistRXInformation(void);
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
void displaySettingPage(void);
void displayPageInformation(u8 pageNum,DataStructure* data);
void displaySettingInfo(u8 Item);
void ShowUnitAndFrame(u8 unitNum);
void displayADIO(float* data);
void displayCtnum(u8 pageNum);
void displayDIDO(float* data);
void displayLoadRatio(float* data);
void displayPower(float* data);
u8 GetDatalength(float* data);
void displayPowerData(float* data);
void displayPDataSpec(float* data);
void displayUData(float* data);
void displayIData(float* data);
void displayPData(float* data);
void displayThduata(float* data);
void displayFreq(float* data);
void displayHarmU(float* data);
void displayHarmI(float* data);
void displayMD(float* data);
void JudgeMinus(float* data,u8 size);
void displayLoadRatioOnlyNum(float* data);
void displayLC(float* data);
void displayTempata(float* data);
void displayPDataSpecVA(float* data);
unsigned char ch;
float Powertemp=0;
float Mdtemp=0;
u8 Hzdisplay=0;
u8 Thdudisplay=0;
u8 LCdisplay=0;
u8 TEMPdisplay=0;
u8 MinusFlag[4]={0};
u8 KEY_Scan(void);
extern u8 ADDR_Num_Single;
extern u8 ADDR_Num_Tens;
extern u8 CT_Single;
extern u8 CT_Tens;
extern u8 CT_Huns;
extern u8 PT_Single;
extern u8 PT_Tens;
extern u8 PT_Huns;
extern u8 MENUnum;
extern u8 BOUNDSEL;
extern int KEY2_ENTER;
extern int KEY2_ENTER_First_sel;
extern int KEY2_ENTER_ADDR_selLocation;
extern int KEY2_CT_selLocation;
extern int KEY2_PT_selLocation;
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#ifndef __MYIIC_H__
#define __MYIIC_H__
#include "ht16c23.h"
#include "gpio.h"
//#include "stm8s_gpio.h"
#define u8 unsigned char
////IO方向设置
////#define SDA_IN() {I_GPIO_Init();}
////#define SDA_OUT() {O_GPIO_Init();}
////IO操作函数
#define IIC_SCL_H() (GPIO_SetBits(GPIOA, GPIO_Pin_10))
#define IIC_SCL_L() (GPIO_ResetBits(GPIOA, GPIO_Pin_10))
#define IIC_SDA_H() (GPIO_SetBits(GPIOA, GPIO_Pin_9))
#define IIC_SDA_L() (GPIO_ResetBits(GPIOA, GPIO_Pin_9))
#define READ_SDA() (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_9))
//IO方向设置
//#define SDA_IN() {GPIOC->CRH&=0XFFFF0FFF;GPIOC->CRH|=8<<12;}
//#define SDA_OUT() {GPIOC->CRH&=0XFFFF0FFF;GPIOC->CRH|=3<<12;}
//IO操作函数
//#define IIC_SCL PCout(12) //SCL
//#define IIC_SDA PCout(11) //SDA
//#define READ_SDA PCin(11) //输入SDA
//IIC所有操作函数
void IIC_Init(void); //初始化IIC的IO口
void IIC_Start(void); //发送IIC开始信号
void IIC_Stop(void); //发送IIC停止信号
void IIC_Send_Byte(u8 txd); //IIC发送一个字节
u8 IIC_Read_Byte(unsigned char ack);//IIC读取一个字节
u8 IIC_Wait_Ack(void); //IIC等待ACK信号
void IIC_Ack(void); //IIC发送ACK信号
void IIC_NAck(void); //IIC不发送ACK信号
void IIC_Write_One_Byte(u8 daddr,u8 addr,u8 data);
u8 IIC_Read_One_Byte(u8 daddr,u8 addr);
void SDA_OUT(void);
void SDA_IN(void);
#endif
#ifndef __OLED_H
#define __OLED_H
#define u8 unsigned char
#define u16 unsigned int
#define ZERO 0
#define ONE 1
#define TWO 2
#define THREE 3
#define FOUR 4
#define FIVE 5
#define SIX 6
#define SEVEN 7
#define EIGHT 8
#define NIGHT 9
#define ZEROP 10
#define ONEP 11
#define TWOP 12
#define THREEP 13
#define FOURP 14
#define FIVEP 15
#define SIXP 16
#define SEVENP 17
#define EIGHTP 18
#define NIGHTP 19
#define EMPTY 20
void OLED_5_Display(u8 wei,u8 shu);
void OLED_5_DisplaySpec(u8 wei,u8 shu);
//void OLED_FX_Display(u8 wei,u8 shu);
//void OLED_ZX_Display(u8 pwr);
//void OLED_1_2_Display(u8 wei,u8 yhshu,u8 ehshu);
//void OLED_3_4_Display(u8 wei,u8 sanhshu,u8 sihshu);
void DisplayFirstLine(u8 location,u8 Num);
void DisplaySecondLine(u8 location,u8 Num);
void DisplayThirdLine(u8 location,u8 Num);
void DisplayFourthLine(u8 location,u8 Num);
void DisplayFirstLineSpec(u8 location,u8 Num);
void DisplaySecondLineSpec(u8 location,u8 Num);
void DisplayThirdLineSpec(u8 location,u8 Num);
void DisplayFourthLineSpec(u8 location,u8 Num);
void DisplayFourthLineSpec2(u8 location,u8 Num);
#endif
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f0xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F0xx_IT_H
#define __STM32F0xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void RCC_IRQHandler(void);
void USART1_IRQHandler(void);
//myself
void EXTI4_15_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32F0xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#ifndef _USART1_H
#define _USART1_H
#include "stm32f0xx.h"
#include "stm32f0xx_dma.h"
#include <stdio.h>
#include <string.h>
unsigned short GetCRC16(unsigned char *pbuf, unsigned short len);
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
//#define F030_RX_BUFSIZE 512
//#define F030_TX_BUFSIZE 256
#define USART1_RX_BUFSIZE 512
#define USART1_TX_BUFSIZE 256
//typedef struct{
// uint8_t RxBuf[F030_RX_BUFSIZE];
// uint16_t RxCount;
// uint8_t RxNewFlag;
//
//}F030RxBUFF_T;
void USART1_Init(void);
void requestData(void);
void USART1SendData(void);
void USART1TxData(void *data,int len);
void DMA_Config(void);
typedef struct
{
u32 slaveID;
u32 Bound;
u32 CTscale;
u32 PTscale;
}SettingParams;
typedef struct {
float ua;
float ub;
float uc;
float ia;
float ib;
float ic;
float pa;
float pb;
float pc;
float pttl;
float qa;
float qb;
float qc;
float qttl;
float sa;
float sb;
float sc;
float sttl;
float freq;
float cosa;
float cosb;
float cosc;
float costtl;
float kwhttli;
float kvarhttli;
float kwhttle;
float kvarhttle;
float thdUa;
float thdUb;
float thdUc;
float thdUttl;
float thdlRmsa;
float thdlRmsb;
float thdlRmsc;
float thdlRmsttl;
float unblU;
float unblI;
float leakCurrent;
float md;//
float loadRatio;
float di1State;
float di2State;
float temp1;
float temp2;
float temp3;
float temp4;
float ctnum;
//
float NetState;
float SIMState;
float SIDState;
}DataStructure;
#endif
#include "flash.h"
#include "stm32f0xx_it.h"
//#include "gizwits_protocol.h"
volatile uint32_t flashWriteOffset = SYS_APP_BAK_SAVE_ADDR_BASE;
volatile uint32_t flashReadOffset = SYS_APP_BAK_SAVE_ADDR_BASE;
/* MCU OTA */
/*擦除指定的Flash页*/
void flash_erase_page(uint8_t flashPage , uint32_t addr_base)
{
HAL_FLASH_Unlock();
FLASH_EraseInitTypeDef f;
f.TypeErase = FLASH_TYPEERASE_PAGES;
f.PageAddress = addr_base+flashPage*FLASH_PAGE_SIZE;
f.NbPages = 1;
uint32_t PageError = 0;
HAL_FLASHEx_Erase(&f, &PageError);
HAL_FLASH_Lock();
}
void flash_erase(uint32_t size , uint32_t addr_base)
{
uint32_t flashPageSum;
uint32_t i;
/*如果小于1024做处理*/
if(size < FLASH_PAGE_SIZE)
size = FLASH_PAGE_SIZE; //
/* 计算需要擦写的Flash页 */
if((size % FLASH_PAGE_SIZE) == 0)
{
flashPageSum = size / FLASH_PAGE_SIZE; //小于一页擦除一页
}
else
{
flashPageSum = (size / FLASH_PAGE_SIZE) + 1; //大于一页擦除n+1页
}
for(i = 0;i<flashPageSum;i++)
{
flash_erase_page(i,addr_base); //基址累加擦除flash
}
}
void writeFlash(uint16_t * buf_to_save , uint16_t len , uint32_t wFlashAddr)
{
uint16_t count=0;
if(wFlashAddr >= 0x08020000)
{
#ifdef DEBUG
printf("Waring:Flash Write Addr Error\r\n");
#endif
flashWriteOffset = SYS_APP_BAK_SAVE_ADDR_BASE;
return;
}
HAL_FLASH_Unlock();
while(count < len)
{
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,(wFlashAddr + count*2),buf_to_save[count]);//写flash函数
count ++;
}
HAL_FLASH_Lock();
}
void readFlash(uint16_t * buf_to_get,uint16_t len , uint32_t readFlashAddr)
{
uint16_t count=0;
while(count<len)
{
buf_to_get[count]=*(uint16_t *)(readFlashAddr + count*2);
count++;
}
}
/*写Flash,控制写长度,Flash地址偏移*/
void wFlashData(uint8_t * buf_to_save , uint16_t len , uint32_t wFlashAddr)
{
uint8_t WriteFlashTempBuf[PIECE_MAX_LEN];//写Flash临时缓冲区
uint16_t WriteFlashTempLen = 0;//写Flash长度
memset(WriteFlashTempBuf,0xEE,sizeof(WriteFlashTempBuf));//写Flash临时缓冲区首先全部填充0xEE
memcpy(WriteFlashTempBuf,buf_to_save,len);//临时缓冲区
WriteFlashTempLen = len;
if(len%2 != 0)
WriteFlashTempLen += 1;//因为Flash只能写半字
writeFlash((uint16_t *)&WriteFlashTempBuf , WriteFlashTempLen/2 , wFlashAddr);
}
void rFlashData(uint8_t * buf_to_get , uint16_t len , uint32_t rFlashAddr)
{
uint8_t ReadFlashTempBuf[PIECE_MAX_LEN];//读Flash临时缓冲区
uint16_t ReadFlashTempLen = 0;//读Flash长度
if(len%2 == 0)
{
ReadFlashTempLen = len;
readFlash((uint16_t *)&ReadFlashTempBuf,ReadFlashTempLen/2 , rFlashAddr);
memcpy(buf_to_get,ReadFlashTempBuf,len);
}
else
{
ReadFlashTempLen = len + 1;//因为Flash只能读半字
readFlash((uint16_t *)&ReadFlashTempBuf,ReadFlashTempLen/2 , rFlashAddr);
memcpy(buf_to_get,ReadFlashTempBuf,len);
}
}
/****IAP*****/
typedef void (*iapfun)(void); //֨ӥһٶگ˽`эքӎ˽.
iapfun jump2app;
u16 iapbuf[1024];
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//设置栈顶指针
//__asm void MSR_MSP(u32 addr)
//{
// MSR MSP, r0 //set Main Stack value
// BX r14
//}
//void iap_load_app(u32 appxaddr)
//{
// if(((*(vu32*)appxaddr)&0x2FFE0000)==0x20000000) //ݬөջַ֥֘ˇرۏר.
// {
// printf("Stack Success!\r\n");
// jump2app=(iapfun)*(vu32*)(appxaddr+4); //ԃۧպëȸ֚׾ٶؖΪԌѲߪʼַ֘(شλַ֘)
// MSR_MSP(*(vu32*)appxaddr); //ԵʼۯAPPבջָ֫(ԃۧպëȸք֚һٶؖԃԚզ؅ջַ֥֘)
// jump2app(); //͸תսAPP.
// }
// else
// {
// printf("Stack Failed!\r\n");
// }
//}
// 代写入的值 地址
void FLASH_EEPROM_Write(uint32_t n,uint32_t add)
{
HAL_FLASH_Unlock(); //解锁
uint32_t PageError = 0;
FLASH_EraseInitTypeDef f;
f.TypeErase = FLASH_TYPEERASE_PAGES;
// f.PageAddress = addr_base+flashPage*FLASH_PAGE_SIZE;
f.NbPages = 1;
if (HAL_FLASHEx_Erase(&f,&PageError) == HAL_OK) //如果结构体中的起始地址0x0801FC00,这一页的数据擦除成功,返回OK
{
printf("擦除 成功\r\n");
__nop();
}
uint32_t writeFlashData = n; //代写入的值
uint32_t addr = add; //写入的地址
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,addr, writeFlashData); //向FLASH中写入
printf("at address:0x%x, read value:%d\r\n", addr, *(__IO uint32_t*)addr);
HAL_FLASH_Lock();
while(1);
}
uint32_t FLASH_EEPROM_Read(uint32_t add)
{
int t;
HAL_FLASH_Unlock();
uint32_t Page = 0;
uint32_t addr = add; //写入的地址
t=*(__IO uint32_t*)addr;
return t;
// return Page;
}
////读取指定地址的字(32位数据)
////faddr:读地址
////返回值:对应数据.
//u32 STMFLASH_ReadWord(u32 faddr)
//{
// return *(vu32*)faddr;
//}
////WriteAddr:起始地址
////WriteData:要写入的数据
//void Test_Write(u32 WriteAddr,u32 WriteData)
//{
// STMFLASH_Write(WriteAddr,&WriteData,1);//写入一个字
//}
////从指定地址开始写入指定长度的数据
////特别注意:因为STM32F4的扇区实在太大,没办法本地保存扇区数据,所以本函数
//// 写地址如果非0XFF,那么会先擦除整个扇区且不保存扇区数据.所以
//// 写非0XFF的地址,将导致整个扇区数据丢失.建议写之前确保扇区里
//// 没有重要数据,最好是整个扇区先擦除了,然后慢慢往后写.
////该函数对OTP区域也有效!可以用来写OTP区!
////OTP区域地址范围:0X1FFF7800~0X1FFF7A0F(注意:最后16字节,用于OTP数据块锁定,别乱写!!)
////WriteAddr:起始地址(此地址必须为4的倍数!!)
////pBuffer:数据指针
////NumToWrite:字(32位)数(就是要写入的32位数据的个数.)
//void STMFLASH_Write(u32 WriteAddr,u32 *pBuffer,u32 NumToWrite)
//{
// FLASH_EraseInitTypeDef FlashEraseInit;
// HAL_StatusTypeDef FlashStatus=HAL_OK;
// u32 SectorError=0;
// u32 addrx=0;
// u32 endaddr=0;
// if(WriteAddr<STM32_FLASH_BASE||WriteAddr%4)return; //非法地址
//
// HAL_FLASH_Unlock(); //解锁
// addrx=WriteAddr; //写入的起始地址
// endaddr=WriteAddr+NumToWrite*4; //写入的结束地址
//
// if(addrx<0X1FFF0000)
// {
// while(addrx<endaddr) //扫清一切障碍.(对非FFFFFFFF的地方,先擦除)
// {
// if(STMFLASH_ReadWord(addrx)!=0XFFFFFFFF)//有非0XFFFFFFFF的地方,要擦除这个扇区
// {
//// FlashEraseInit.TypeErase=FLASH_TYPEERASE_SECTORS; //擦除类型,扇区擦除
// FlashEraseInit.Sector=STMFLASH_GetFlashSector(addrx); //要擦除的扇区
// FlashEraseInit.NbSectors=1; //一次只擦除一个扇区
//// FlashEraseInit.VoltageRange=FLASH_VOLTAGE_RANGE_3; //电压范围,VCC=2.7~3.6V之间!!
// if(HAL_FLASHEx_Erase(&FlashEraseInit,&SectorError)!=HAL_OK)
// {
// break;//发生错误了
// }
// }else addrx+=4;
// FLASH_WaitForLastOperation(FLASH_WAITETIME); //等待上次操作完成
// }
// }
// FlashStatus=FLASH_WaitForLastOperation(FLASH_WAITETIME); //等待上次操作完成
// if(FlashStatus==HAL_OK)
// {
// while(WriteAddr<endaddr)//写数据
// {
// if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,WriteAddr,*pBuffer)!=HAL_OK)//写入数据
// {
// break; //写入异常
// }
// WriteAddr+=4;
// pBuffer++;
// }
// }
// HAL_FLASH_Lock(); //上锁
//}
#include "delay.h"
#include "key.h"
#include "stm32f0xx_it.h"
#include "stm32f0xx_tim.h"
#define u8 unsigned char
#define u16 unsigned int
u8 keycnter=0;
u8 KeyPressFlag[4]={0};
static int8_t fac_us=0;//us
static int16_t fac_ms=0;//ms
u8 Delay_cnter=0;
u16 SendDelay_Counter=0;
void TIM3_Init(void)//周期50ms
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //tim3时钟使能,APB时钟48M
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; //分频系数为1
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
TIM_TimeBaseInitStructure.TIM_Period = 999;
TIM_TimeBaseInitStructure.TIM_Prescaler = 959; //定时500ms
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //允许定时器3更新中断
TIM_Cmd(TIM3,ENABLE); //使能定时器3
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //定时器3中断
NVIC_InitStructure.NVIC_IRQChannelPriority = 2; //优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update) != RESET) //溢出中断
{
HAL_TIM_PeriodElapsedCallback();
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //清除中断标志位
}
void delay_init()
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);//选择外部时钟 HCLK/8
fac_us=SystemCoreClock/8000000; //为系统时钟的1/8
fac_ms=(int16_t)fac_us*1000;//每个ms需要的systick时钟数
}
//延时Nus
void delay_us(int32_t nus)
{
int32_t temp;
SysTick->LOAD=nus*fac_us; //时间加载
SysTick->VAL=0x00; //清空计数器
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数
do
{
temp=SysTick->CTRL;
}
while(temp&0x01&&!(temp&(1<<16)));//等待时间到达
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器
SysTick->VAL =0X00; //清空计数器
}
//void delay_us(int32_t nus)
//{
// for( ;nus>0;nus--)
// {
// __NOP();
//
// }
//}
//延时Nms
void delay_ms(int16_t nms)
{
int32_t temp;
SysTick->LOAD=(int32_t)nms*fac_ms;//时间加载(SysTick->LOAD为24bit)
SysTick->VAL =0x00; //清空计数器
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数
do
{
temp=SysTick->CTRL;
}
while(temp&0x01&&!(temp&(1<<16)));//等待时间到达
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器
SysTick->VAL =0X00; //清空计数器
}
void HAL_TIM_PeriodElapsedCallback()
{
static u8 key_up=1;//按键按松开标志
Delay_cnter++;
SendDelay_Counter++;
if(key_up&&(KEY1==0||KEY2==0||KEY3==0 ||KEY4==0))
{
key_up=0;
delay_ms(10);
if(KEY1==0)
{
KeyPressFlag[0]=1;
}
else if(KEY2==0)
{
KeyPressFlag[1]=1;
}
else if(KEY3==0)
{
KeyPressFlag[2]=1;
}
else if(KEY4==0)
{
KeyPressFlag[3]=1;
}
}
else if(KEY1==1 && KEY2==1 && KEY3==1 && KEY4==1)
{
key_up=1;
}
}
/**
******************************************************************************
* File Name : gpio.c
* Description : This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure GPIO */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
void MX_GPIO_Init(void)
{
// GPIO_InitTypeDef GPIO_InitStruct = {0};
// /* GPIO Ports Clock Enable */
// __HAL_RCC_GPIOF_CLK_ENABLE();
// __HAL_RCC_GPIOA_CLK_ENABLE();
// __HAL_RCC_GPIOB_CLK_ENABLE();
// /*Configure GPIO pins : PA9 PA10 */
// GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
// RCC_APB2PeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType =GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
/* USER CODE BEGIN 2 */
void O_GPIO_Init()
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
// __HAL_RCC_GPIOF_CLK_ENABLE();
// __HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pins : PA9 PA10 */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void I_GPIO_Init()
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
// __HAL_RCC_GPIOF_CLK_ENABLE();
// __HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pins : PA9 PA10 */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
}
/* USER CODE END 2 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#include "ht16c23.h"
#include "myiic.h"
#include "gpio.h"
void init_ht16c23(void){
// GPIO_Init(GPIOC, GPIO_PIN_5,GPIO_MODE_OUT_PP_HIGH_FAST);
IIC_Init();
I2CWriteSingle(0x80,0x00);
I2CWriteSingle(0x82,0x03);
I2CWriteSingle(0x84,0x03);
I2CWriteSingle(0x86,0x00);
I2CWriteSingle(0x88,0x00);
I2CWriteSingle(0x8a,0x00);
// I2CWriteSingle(0x82,0x11);
// I2CWriteSingle(0x84,0x03);
// I2CWriteSingle(0x86,0x00);
// I2CWriteSingle(0x88,0x00);
// I2CWriteSingle(0x8a,0x30);
// I2CWriteSingle(0x80,0x00);
ht16c23_clear();
}
void I2CWriteSingle(char I2CData,char I2CData_sub)
{
IIC_Start();
IIC_Send_Byte(0x7C); //器件地址(写)
IIC_Wait_Ack();
IIC_Send_Byte(I2CData);
IIC_Wait_Ack();
IIC_Send_Byte(I2CData_sub);
IIC_Wait_Ack();
IIC_Stop();
}
void ht16c23_clear(void){
int i;
IIC_Start();
IIC_Send_Byte(0x7C);//器件地址(写)
IIC_Wait_Ack();
IIC_Send_Byte(0x80);//设置显示数据输入/输出命令
IIC_Wait_Ack();
IIC_Send_Byte(0x00);//设置开始地址
IIC_Wait_Ack();
for(i=0;i<0x33;i++){ //??? i只要比0大就可以了
IIC_Send_Byte(0x00); //IIC发送一个字节
IIC_Wait_Ack();
}
IIC_Stop();
}
//write ram 位选 段选
void ht16c23_write_one_byte2ram(u8 addr ,u8 data){
IIC_Start();
IIC_Send_Byte(0x7C);//器件地址(写)
IIC_Wait_Ack();
IIC_Send_Byte(0x80);//写起始地址
IIC_Wait_Ack();
IIC_Send_Byte(addr); //位选
IIC_Wait_Ack();
IIC_Send_Byte(data);//段选
IIC_Wait_Ack();
IIC_Stop();
}
////读操作
//u8 ht16c23_read_one_byte2ram(u8 addr){
// u8 temp;
// IIC_Start();
// IIC_Send_Byte(0x7C);//器件地址(写)
// IIC_Wait_Ack();
// IIC_Send_Byte(0x80);//写起始地址
// IIC_Wait_Ack();
// IIC_Send_Byte(0x00);//设置开始地址
// IIC_Wait_Ack();
// IIC_Start();
// IIC_Send_Byte(0x7D);//器件地址(读)
// IIC_Wait_Ack();
// temp = IIC_Read_Byte(addr);//原来是0,我改成addr
//
// IIC_Stop();
// return temp;
//}
////写多个字节
//void ht16c23_write_bytes2ram(u8 addr ,u8 *data, u8 len){
// int i;
// IIC_Start();
// IIC_Send_Byte(0x7C);
// IIC_Wait_Ack();
// IIC_Send_Byte(0x80);
// IIC_Wait_Ack();
// IIC_Send_Byte(addr);//设置开始地址
// IIC_Wait_Ack();
// for(i=0;i<len;i++){
// IIC_Send_Byte(data[i]);
// IIC_Wait_Ack();
// }
// IIC_Stop();
//}
//com
//seg
//void ht16c23_write_val(u8 com,u8 seg, u8 seg_val){
// u8 read_seg_val;
// seg_val&=0x01;
// read_seg_val=ht16c23_read_one_byte2ram(seg>>1);
// if(seg%2){
// read_seg_val|=(seg_val<<(com+4))|((~(1<<(com+4)))&read_seg_val);
// }else{
// read_seg_val|=(seg_val<<(com))|((~(1<<(com)))&read_seg_val);
// }
// ht16c23_write_one_byte2ram(seg>>1, read_seg_val);
//}
#include "key.h"
//#include "delay.h"
#include "ht16c23.h"
#include "delay.h"
#include "string.h"
//#define u8 unsigned char
//#define u16 unsigned int
int MENUnum =0;
int KEY2_ENTER=0;
int KEY2_ENTER_First_sel=0;
int KEY2_ENTER_Second=0;
int KEY2_ENTER_ADDR_selLocation=1;
u8 BOUNDSEL=1;
int KEY2_CT_selLocation=1;
int KEY2_PT_selLocation=1;
u8 ADDR_Num_Single=0;
u8 ADDR_Num_Tens=0;
u8 CT_Single=1;
u8 CT_Tens=0;
u8 CT_Huns=0;
u8 PT_Single=1;
u8 PT_Tens=0;
u8 PT_Huns=0;
extern u8 tempArr12[16];
extern u8 tempArr34[16];
extern u8 KeyPressFlag[4];
extern void USART1SendData();
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : PA5 */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
}
/*
*********************************************************************************************************
* 函 数 名: void keyHandle()
* 功能说明: 处理按键响应
* 形 参:
* 返 回 值:
*********************************************************************************************************
*/
void keyHandle(void)
{
if(KeyPressFlag[0]==1)//KEY1按下
{
if(KEY2_ENTER==0)
{
MENUnum+=1;
if(MENUnum>16)
MENUnum=0;
ht16c23_clear();
memset(tempArr12,0,16);
memset(tempArr34,0,16);
}
else if(KEY2_ENTER==1)
{
KEY2_ENTER_First_sel+=1;
if(KEY2_ENTER_First_sel>3) KEY2_ENTER_First_sel=0;
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==0 && KEY2_ENTER==2)//设置ADDR时
{
KEY2_ENTER_ADDR_selLocation++;
if(KEY2_ENTER_ADDR_selLocation>2)
KEY2_ENTER_ADDR_selLocation=1;// 选择3 4位
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==1 && KEY2_ENTER==2 ) ////设置Bound时
{
BOUNDSEL++;
if(BOUNDSEL>4) BOUNDSEL=1;//选择1-4级的波特率
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==2 && KEY2_ENTER==2) // 设置CT时
{
KEY2_CT_selLocation++;
if(KEY2_CT_selLocation>3) KEY2_CT_selLocation=1;//选择 2 3 4位
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==3 && KEY2_ENTER==2 ) ////设置PT时
{
KEY2_PT_selLocation++;
if(KEY2_PT_selLocation>3) KEY2_PT_selLocation=1;//选择 2 3 4位
ht16c23_clear();
}
KeyPressFlag[0]=0;
}
else if(KeyPressFlag[1]==1)//KEY2
{
KEY2_ENTER+=1;//回车键进入设置的不同层级
if(KEY2_ENTER>2)
{
USART1SendData();
KEY2_ENTER=0;
KEY2_ENTER_First_sel=0;
}
ht16c23_clear();
KeyPressFlag[1]=0;
}
else if(KeyPressFlag[2]==1)//KEY3
{
if(KEY2_ENTER==0)
{
MENUnum-=1;//翻页
if(MENUnum<0)
MENUnum=16;
ht16c23_clear();
memset(tempArr12,0,16);
memset(tempArr34,0,16);
}
else if(KEY2_ENTER==1)
{
KEY2_ENTER_First_sel--;
if(KEY2_ENTER_First_sel<0) KEY2_ENTER_First_sel=3; //上下选择设置的选项
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==0 && KEY2_ENTER==2&&KEY2_ENTER_ADDR_selLocation==1)
{
ADDR_Num_Single++;
if(ADDR_Num_Single>9) ADDR_Num_Single=0;//设置位上面的数值
}
else if(KEY2_ENTER_First_sel==0 && KEY2_ENTER==2&&KEY2_ENTER_ADDR_selLocation==2)
{
ADDR_Num_Tens++;
if(ADDR_Num_Tens>9) ADDR_Num_Tens=0;//设置位上面的数值
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==1 && KEY2_ENTER==2)
{
BOUNDSEL--;
if(BOUNDSEL<1) BOUNDSEL=4;
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==2 && KEY2_ENTER==2 )
{
if(KEY2_CT_selLocation==1)
{
CT_Single+=1;
if(CT_Single>9)
CT_Single=0;
}
if(KEY2_CT_selLocation==2)
{
CT_Tens+=1;
if(CT_Tens>9)
CT_Tens=0;
}
if(KEY2_CT_selLocation==3)
{
CT_Huns+=1;
if(CT_Huns>9)
CT_Huns=0;
}
ht16c23_clear();
}
else if(KEY2_ENTER_First_sel==3 && KEY2_ENTER==2 )
{
if(KEY2_PT_selLocation==1)
{
PT_Single+=1;
if(PT_Single>9)
PT_Single=0;
}
if(KEY2_PT_selLocation==2)
{
PT_Tens+=1;
if(PT_Tens>9)
PT_Tens=0;
}
if(KEY2_PT_selLocation==3)
{
PT_Huns+=1;
if(PT_Huns>9)
PT_Huns=0;
}
ht16c23_clear();
}
KeyPressFlag[2]=0;
}
else if(KeyPressFlag[3]==1)//KEY4
{
if(KEY2_ENTER>0)
KEY2_ENTER-=1;
ht16c23_clear();
KeyPressFlag[3]=0;
}
}
#include "led.h"
#include "usart.h"
#include "delay.h"
extern DataStructure DataStruc;
extern u8 Delay_cnter;
void LEDInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_3|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_Level_3;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
void LEDHandle(void)
{
if(Delay_cnter>50)
{
if(DataStruc.SIDState==1)
TURNLED1();
if(DataStruc.NetState==1)
TURNLED2();
if(DataStruc.SIMState==1)
TURNLED3();
else if(DataStruc.SIDState==0&&DataStruc.NetState==0&&DataStruc.SIMState==0)
{
TURNLED1();
TURNLED2();
TURNLED3();
}
Delay_cnter=0;
}
}
#include "myiic.h"
#include "delay.h"
#include "gpio.h"
#define u8 unsigned char
//IO方向设置
//#define SDA_IN() {I_GPIO_Init();}
//#define SDA_OUT() {O_GPIO_Init();}
void SDA_OUT(void)
{
O_GPIO_Init();
}
void SDA_IN(void)
{
I_GPIO_Init();
}
//初始化IIC
void IIC_Init(void)
{
MX_GPIO_Init();
// GPIO_Init(GPIOA, GPIO_PIN_9,GPIO_MODE_OUT_PP_HIGH_FAST);
// GPIO_Init(GPIOA, GPIO_PIN_10,GPIO_MODE_OUT_PP_HIGH_FAST);
IIC_SCL_H();
IIC_SDA_H();
}
//产生IIC起始信号
void IIC_Start(void)
{
SDA_OUT(); //sda线输出
IIC_SDA_H();
IIC_SCL_H();
delay_us(4);
IIC_SDA_L();//START:when CLK is high,DATA change form high to low
delay_us(4);
IIC_SCL_L();//钳住I2C总线,准备发送或接收数据
}
//产生IIC停止信号
void IIC_Stop(void)
{
SDA_OUT();//sda线输出
IIC_SCL_L();
IIC_SDA_L();//STOP:when CLK is high DATA change form low to high
delay_us(4);
IIC_SCL_H();
IIC_SDA_H();//发送I2C总线结束信号
delay_us(4);
}
//等待应答信号到来
//返回值:1,接收应答失败
// 0,接收应答成功
u8 IIC_Wait_Ack(void)
{
u8 ucErrTime=0;
SDA_IN(); //SDA设置为输入
IIC_SDA_H();delay_us(1);
IIC_SCL_H();delay_us(1);
while(READ_SDA())
{
ucErrTime++;
if(ucErrTime>250)
{
IIC_Stop();
return 1;
}
}
IIC_SCL_L();//时钟输出0
return 0;
}
//产生ACK应答
void IIC_Ack(void)
{
IIC_SCL_L();
SDA_OUT();
IIC_SDA_L();
delay_us(2);
IIC_SCL_H();
delay_us(2);
IIC_SCL_L();
}
//不产生ACK应答
void IIC_NAck(void)
{
IIC_SCL_L();
SDA_OUT();
IIC_SDA_H();
delay_us(2);
IIC_SCL_H();
delay_us(2);
IIC_SCL_L();
}
//IIC发送一个字节
//返回从机有无应答
//1,有应答
//0,无应答
void IIC_Send_Byte(u8 txd)
{
u8 t;
SDA_OUT();
IIC_SCL_L();//拉低时钟开始数据传输
for(t=0;t<8;t++)
{
if((txd&0x80)>>7){
IIC_SDA_H();
}else{
IIC_SDA_L();
}
txd<<=1;
delay_us(2); //对TEA5767这三个延时都是必须的
IIC_SCL_H();
delay_us(2);
IIC_SCL_L();
delay_us(2);
}
}
////读1个字节,ack=1时,发送ACK,ack=0,发送nACK
//u8 IIC_Read_Byte(unsigned char ack)
//{
// unsigned char i,receive=0;
// SDA_IN();//SDA设置为输入
// for(i=0;i<8;i++ )
// {
// IIC_SCL_L();
// delay_us(2);
// IIC_SCL_H();
// receive<<=1;
// if(READ_SDA())receive++;
// delay_us(1);
// }
// if (!ack)
// IIC_NAck();//发送nACK
// else
// IIC_Ack(); //发送ACK
// return receive;
//}
This diff is collapsed.
This diff is collapsed.
[EXTDLL]
Count=0
This diff is collapsed.
This diff is collapsed.
--cpu Cortex-M0
"..\obj\main.o"
"..\obj\stm32f0xx_it.o"
"..\obj\system_stm32f0xx.o"
"..\obj\startup_stm32f0xx.o"
"..\obj\delay.o"
"..\obj\gpio.o"
"..\obj\ht16c23.o"
"..\obj\key.o"
"..\obj\myiic.o"
"..\obj\oled0561.o"
"..\obj\usart.o"
"..\obj\led.o"
"..\obj\stm32f0xx_gpio.o"
"..\obj\stm32f0xx_rcc.o"
"..\obj\stm32f0xx_misc.o"
"..\obj\stm32f0xx_usart.o"
"..\obj\stm32f0xx_crc.o"
"..\obj\stm32f0xx_i2c.o"
"..\obj\stm32f0xx_syscfg.o"
"..\obj\stm32f0xx_tim.o"
"..\obj\stm32f0xx_dma.o"
--library_type=microlib --ro-base 0x08000000 --entry 0x08000000 --rw-base 0x20000000 --entry Reset_Handler --first __Vectors --strict --summary_stderr --info summarysizes --map --load_addr_map_info --xref --callgraph --symbols
--info sizes --info totals --info unused --info veneers
--list ".\STM32F030Demo.map" -o ..\OBJ\STM32F030Demo.axf
\ No newline at end of file
This diff is collapsed.
File added
..\obj\delay.o: ..\HARDWARE\src\delay.c
..\obj\delay.o: ..\SYSTEM\delay.h
..\obj\delay.o: ..\User\stm32f0xx.h
..\obj\delay.o: ..\CORE\core_cm0.h
..\obj\delay.o: D:\MDK5\ARM\ARMCC\Bin\..\include\stdint.h
..\obj\delay.o: ..\CORE\core_cmInstr.h
..\obj\delay.o: ..\CORE\core_cmFunc.h
..\obj\delay.o: ..\User\system_stm32f0xx.h
..\obj\delay.o: ..\User\stm32f0xx_conf.h
..\obj\delay.o: ..\STM32F03x_FWLib\inc\stm32f0xx_gpio.h
..\obj\delay.o: ..\User\stm32f0xx.h
..\obj\delay.o: ..\STM32F03x_FWLib\inc\stm32f0xx_rcc.h
..\obj\delay.o: ..\STM32F03x_FWLib\inc\stm32f0xx_usart.h
..\obj\delay.o: ..\STM32F03x_FWLib\inc\stm32f0xx_misc.h
..\obj\delay.o: ..\HARDWARE\inc\key.h
..\obj\delay.o: ..\User\stm32f0xx_it.h
..\obj\delay.o: ..\STM32F03x_FWLib\inc\stm32f0xx_tim.h
File added
File added
..\obj\delay_1.o: ..\SYSTEM\delay.c
..\obj\delay_1.o: ..\SYSTEM\delay.h
..\obj\delay_1.o: ..\User\stm32f0xx_it.h
..\obj\delay_1.o: ..\User\stm32f0xx.h
..\obj\delay_1.o: ..\CORE\core_cm0.h
..\obj\delay_1.o: D:\MDK5\ARM\ARMCC\Bin\..\include\stdint.h
..\obj\delay_1.o: ..\CORE\core_cmInstr.h
..\obj\delay_1.o: ..\CORE\core_cmFunc.h
..\obj\delay_1.o: ..\User\system_stm32f0xx.h
..\obj\delay_1.o: ..\User\stm32f0xx_conf.h
..\obj\delay_1.o: ..\STM32F03x_FWLib\inc\stm32f0xx_gpio.h
..\obj\delay_1.o: ..\User\stm32f0xx.h
..\obj\delay_1.o: ..\STM32F03x_FWLib\inc\stm32f0xx_rcc.h
..\obj\delay_1.o: ..\STM32F03x_FWLib\inc\stm32f0xx_usart.h
..\obj\delay_1.o: ..\STM32F03x_FWLib\inc\stm32f0xx_misc.h
File added
File added
This diff is collapsed.
File added
File added
This diff is collapsed.
File added
This diff is collapsed.
File added
This diff is collapsed.
File added
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment