1: void GPIO_Configuration(void)
Add GPIOA configuration
void GPIO_Configuration(void)
{
GPIO_DeInit(GPIOD);
/* Configure PD0 (LED1) as output push-pull low (led switched on) */
GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
/* GPIOD reset */
GPIO_DeInit(GPIOC);
/* Configure PD0 (LED1) as output push-pull low (led switched on) */
GPIO_Init(GPIOC, GPIO_PIN_5 , GPIO_MODE_OUT_PP_HIGH_SLOW);
GPIO_Init(GPIOC, GPIO_PIN_6, GPIO_MODE_OUT_PP_HIGH_SLOW);
GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_FAST);}
2: void HC595SendData(u8 SendData)
send data to HC595 Using GPIOA+SPI
GPIOC.6---- SER
GPIOC.5---- SCLK
GPIOC.4---- RCLK
void HC595SendData(u8 SendData)
{
#if Comm_MODE
while (SPI_GetFlagStatus( SPI_FLAG_TXE) == RESET);
SPI_SendData(SendData);
while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET);
SPI_ReceiveData(); /*读取因上面发送数据产生的无效数据*/
#else
// 寄存器(可赋值):不优化290KHz,最高速度优化:319KHz
u8 i;
for(i=0; i<8; i++)
{
if(SendData<ODR |= GPIO_PIN_6; //SER
else GPIOC->ODR &=~GPIO_PIN_6;
GPIOC->ODR |= GPIO_PIN_5; //SCLK
GPIOC->ODR &=~GPIO_PIN_5;
}
#endif
}
3: void sdata(void)
Send 8 byte data to HC595
void sdata(void)
{
HC595SendData(segbit[m]);
HC595SendData(fseg[disbuf[m]]);
GPIOC->ODR |= GPIO_PIN_4; //RCLK
GPIOC->ODR &=~GPIO_PIN_4;
m++;
if(m==8)
{
m=0;
}
}
**
1.declare m as globe variable
unsigned char m;
#define Comm_MODE 1/0
2.declare segbit , fseg and disbuf variable
U8 fseg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char segbit[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char disbuf[8]={0,0,0,0,0,0,0,0};
3.should include the head file
#include "stm8s_spi.h"
上一篇:【STM8】SPI通讯
下一篇:stm8 硬件SPI
推荐阅读最新更新时间:2024-11-05 10:35
设计资源 培训 开发板 精华推荐
- GSH_Bed 铝基板加热平台
- TB67B000FG 三相无刷直流电机驱动器评估板
- 使用 Analog Devices 的 LTC3119IUFD 的参考设计
- LT1033CT 负 5V 线性稳压器的典型应用电路
- 使用 Analog Devices 的 LTC3374AHUHF 的参考设计
- BLDC
- NCV706278FULLGEVK:LIN 汽车步进电机驱动器套件
- RSO-2412S 12V、83mA输出DC/DC转换器典型应用电路
- ZXGD3101EV1,评估板演示 MOSFET 的同步整流和驱动
- OM7962: 低噪声放大器BFU520、BFU530和BFU550客户评估套件,适用于SOT143封装的晶体管