赞
踩
一、原理图
二、程序代码
#include "led.h"
#include "delay.h"
void led_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE); //使能PB,PE端口时钟
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_4|GPIO_Pin_5);
}
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_clk=1;
}
}
void led_show_data(u8 *showData,u8 length)
{
u8 i;
led_stb=0;
led_write_data(0x40); //设置数据命令
led_stb=1;
led_stb=0;
led_write_data(0xc0); //设置显示地址
for(i=0;i<length;i++)
led_write_data(showData[i]); //设置显示数据
led_stb=1;
led_stb=0;
led_write_data(LED_ON|LED_BRIGHTNESS_3); //设置显示控制命令
led_stb=1;
}
int main(void)
{
u8 ledData[16];
delay_init();
led_init();
while(1)
{
ledData[0]=0xff;
ledData[1]=0xff;
ledData[2]=0xff;
ledData[3]=0xff;
ledData[4]=0xff;
ledData[5]=0xff;
ledData[6]=0xff;
ledData[7]=0xff;
ledData[8]=0xff;
ledData[9]=0xff;
ledData[10]=0xff;
ledData[11]=0xff;
ledData[12]=0xff;
ledData[13]=0xff;
ledData[14]=0xff;
ledData[15]=0xff;
led_show_data(ledData,sizeof(ledData));
delay_ms(1000);
ledData[0]=0x00;
ledData[1]=0x00;
ledData[2]=0x00;
ledData[3]=0x00;
ledData[4]=0x00;
ledData[5]=0x00;
ledData[6]=0x00;
ledData[7]=0x00;
ledData[8]=0x00;
ledData[9]=0x00;
ledData[10]=0x00;
ledData[11]=0x00;
ledData[12]=0x00;
ledData[13]=0x00;
ledData[14]=0x00;
ledData[15]=0x00;
led_show_data(ledData,sizeof(ledData));
delay_ms(1000);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。