先上图
源代码:
#include "example.h"
#include "gd32f20x.h"
#include "colibri_bsp_led.h"
#if (EVB_EXAMPLE == LED_EXAMPLE)
#define uchar unsigned char
char bright=0x04; /*亮度设置*/
/********************************* 定义MAX7219内部寄存器***************/
#define reg_decode 0x09 /**/
#define reg_intensity 0x0a /**/
#define reg_scan_limit 0x0b /**/
#define reg_shutdown 0x0c /**/
#define reg_display_test 0x0f /**/
#define clk_0 GPIO_ResetBits(GPIOE,GPIO_PIN_2);
#define clk_1 GPIO_SetBits(GPIOE,GPIO_PIN_2);
#define load_0 GPIO_ResetBits(GPIOE,GPIO_PIN_1);
#define load_1 GPIO_SetBits(GPIOE,GPIO_PIN_1);
#define dataa_0 GPIO_ResetBits(GPIOE,GPIO_PIN_0);
#define dataa_1 GPIO_SetBits(GPIOE,GPIO_PIN_0);
/*************定义显示常数表格************/
static const struct{
char asci;
char segs;
}font[21]=
{{' ',0x00},{'0',0x7e},{'1',0x30},{'2',0x6d},{'3',0x79},{'4',0x33},{'5',0x5b},{'6',0x5f},{'7',0x70},{'8',0x7f},{'9',0x7b},
{'A',0x77},{'b',0x1f},{'C',0x4e},{'d',0x3d},{'E',0x4f},{'F',0x47},{'H',0x37},{'L',0x0e},{'r',0x46},{'P',0x67}
};//5
/*****************发送一字节串行数据******************/
static void Sendbyte(uchar dataout)
{char i;
load_0;
for(i=8;i>0;i--)
{
uchar mask=1<<(i-1);
clk_0;
if(dataout&mask)
dataa_1;
if((dataout&mask)==0)
dataa_0;
clk_1;
}
}
/*********写入数据**********/
static void Write(uchar reg_number,uchar dataout)
{
load_0;
Sendbyte(reg_number);
Sendbyte(dataout);
load_1;
}
/***********查段码表将显示字符转换为显示段码************/
static uchar Lookupcode(char character)
{char i;
for(i=0;i<21;i++)
{if(character==font.asci)
{return font.segs;}
}
return (0);
}
void display(char digit,char character)
{
Write(digit,Lookupcode(character));
}
/**********初始化************/
void init(void)
{char i;
dataa_1;
load_1;
clk_1;
Write(reg_scan_limit,3);
Write(reg_decode,0x00);
Write(reg_shutdown,1); /*结束停机测试,正常工作*/
Write(reg_display_test,0); /*结束显示测试,正常工作*/
for(i=1;i<=8;i++)
{Write(i,0x00);
} /*关闭全部显示器*/
}
/* 用户应用程序入口函数 */
int main(void)
{
int i;
char brightness;
/* 配置使能评估板上的设备 */
EvbSetupBoard();
PRINTF("感谢使用Colibri开发板\r\n");
PRINTF("\r\n");
PRINTF("##### LED 实验 #####\r\n");
PRINTF("\r\n");
init();
Write(reg_shutdown,1);
Write(reg_display_test,0);
brightness=bright&0x0f;
Write(reg_intensity,brightness);
display(0x01,'H');
display(0x02,'0');
display(0x03,'P');
display(0x04,'E');
while(1)
{
// for (i = 0; i< 0x7fffff; i++);
// EvbLedControl(LED1, LED_ON);
// EvbLedControl(LED2, LED_ON);
// EvbLedControl(LED3, LED_ON);
//
// for (i = 0; i< 0x7fffff; i++);
// EvbLedControl(LED1, LED_OFF);
// EvbLedControl(LED2, LED_OFF);
// EvbLedControl(LED3, LED_OFF);
}
}
#endif
|
|