二、驱动程序
#include "led.h"
void led_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_SetBits(GPIOC,GPIO_Pin_0);
GPIO_SetBits(GPIOD,GPIO_Pin_13);
GPIO_SetBits(GPIOE,GPIO_Pin_6);
}
void led_delay(u8 i)
{
while(i>0)
i--;
}
void led_write_data(u8 data)
{
u8 i;
for(i=0;i<8;i++)
{
led_clk=0;
if(data&0x01)
led_dio=1;
else
led_dio=0;
data>>=1;
led_delay(2);
led_clk=1;
}
}
void led_show_data(u8 *showData)
{
led_stb=0;
led_delay(2);
led_write_data(0x00); //设置数据命令
led_stb=1;
led_delay(2);
led_stb=0;
led_delay(2);
led_write_data(0x40); //设置数据命令
led_stb=1;
led_delay(2);
led_stb=0;
led_delay(2);
led_write_data(0xc0); //设置显示地址
led_write_data(showData[0]); //设置显示数据
led_write_data(0X00); //设置显示数据
led_write_data(showData[1]); //设置显示数据
led_write_data(0X00); //设置显示数据
led_write_data(showData[2]); //设置显示数据
led_write_data(0X00); //设置显示数据
led_write_data(showData[3]); //设置显示数据
led_stb=1;
led_delay(2);
led_stb=0;
led_delay(2);
led_write_data(LED_ON|LED_BRIGHTNESS_3); //设置显示控制命令
led_stb=1;
led_delay(2);
}
|