📄 led.c
字号:
/*************************************************************************************
* Copyright (c) 2005 by National ASIC System Engineering Research Center.
* PROPRIETARY RIGHTS of ASIC are involved in the subject matter of this
* material. All manufacturing, reproduction, use, and sales rights
* pertaining to this subject matter are governed by the license agreement.
* The recipient of this software implicitly accepts the terms of the license.
*
* File Name: led.c
*
* File Description:
* The file consists of the function used to config uart
*
* Function Description:
* STATUS ModuleLed(void);
* void LedDisPlay(U8 data[]);
* void GPIO_Init(void);
* void Hex2Seg (U8 data[], U8 * p);
* void LedOut(U8 data[], U32 times);
* void LedUpdate(void);
* void delay(int cycle);
*
*
* Created by Wuer xiao
**************************************************************************************/
//#include "garfield.h"
#include "led.h"
#include <string.h>
U16 prochip[4] = {0xce40,0x6040,0x6e40,0x9c40};
U16 Num[10];
U16 LedNum[10];
U16 Numdot[10];
#define ROLL; // 是否以滚屏方式显示: no define: 不滚屏
void init_Num()
{
int i;
Num[0] = sect2 + sect3 + sect4 + sect5 + sect6 + sect7;
Num[1] = sect5 + sect6;
Num[2] = sect7 + sect6 + sect1 + sect3 + sect4;
Num[3] = sect7 + sect6 + sect1 + sect4 + sect5;
Num[4] = sect2 + sect1 + sect5 + sect6;
Num[5] = sect7 + sect2 + sect1 + sect4 + sect5;
Num[6] = sect1 + sect2 + sect3 + sect4 + sect5 + sect7;
Num[7] = sect5 + sect6 + sect7;
Num[8] = sect1 + sect2 + sect3 + sect4 + sect5 + sect6 + sect7;
Num[9] = sect7 + sect6 + sect5 + sect2 + sect1;
for(i=0;i<10;i++)
{
LedNum[i] = (Num[i] << 8) + 0x00;
Numdot[i] = LedNum[i] + (dot << 8);
}
/*
LedNum[0] = (Num[0] << 8) + 0x00;
LedNum[1] = (Num[1] << 8) + 0x00;
LedNum[2] = (Num[2] << 8) + 0x00;
LedNum[3] = (Num[3] << 8) + 0x00;
LedNum[4] = (Num[4] << 8) + 0x00;
LedNum[5] = (Num[5] << 8) + 0x00;
LedNum[6] = (Num[6] << 8) + 0x00;
LedNum[7] = (Num[7] << 8) + 0x00;
LedNum[8] = (Num[8] << 8) + 0x00;
LedNum[9] = (Num[9] << 8) + 0x00;
*/
}
int ModuleLed(void)
{
/* GPIO initialized */
Led_Init();
init_Num();
return E_OK;
}
void Led_Init(void)
{
*(RP)PORTG_SEL = 0xF7; // 设定GPIO口 PD0/1/2 为通用口
*(RP)PORTG_DIR = 0x0; // 设定GPIO口 PD0/1/2 为数据输出
*(RP)PORTE_SEL = 0x03C0;
*(RP)PORTE_DIR = 0x0;
}
void sLedout(U16 data, unsigned char Bit_i)
{
int Segment_i,i;
U16 Segment_Data;
U16 tempData;
U32 portgdatatemp;
portgdatatemp = (*(volatile unsigned long *)PORTG_DATA)&0x1f;
Segment_Data = data;
for (Segment_i = 0; Segment_i < 16; Segment_i++) // 将7段译码值依次串行输入到GPIO口中
{
tempData=(Segment_Data<<(15-Segment_i)) & 0x8000; // 得到一段发光管的译码值
*(RP)PORTG_DATA = ((U8)(tempData>>8)) | portgdatatemp ; // 写入74HC595的输入端,同时拉低PD2
//*(RP)PORTG_DATA = (U8)(tempData>>8) ;
*(RP)PORTG_DATA |= 0x40; // 拉高PD2,触发74HC595,移位寄存
}
//delay(0x100);
LedUpdate(); // 显示到LED上
*(RP)PORTE_DATA = 0x0200>>Bit_i;
}
void LedOut(U16 data[], U32 times)
{
int Segment_i,Bit_i,i;
U16 Segment_Data;
U16 tempData;
for(i = 0; i < times;i++) //
{
for (Bit_i = 0; Bit_i < 4 ;Bit_i++) // 依次串行导入4个led的显示内容
{
Segment_Data=*(data + Bit_i); // 获得一个led显示的码值
for (Segment_i = 0; Segment_i < 16; Segment_i++) // 将7段译码值依次串行输入到GPIO口中
{
tempData=(Segment_Data<<(15-Segment_i)) & 0x8000; // 得到一段发光管的译码值
*(RP)PORTG_DATA = (U8)(tempData>>8); // 写入74HC595的输入端,同时拉低PD2
*(RP)PORTG_DATA = 0x40; // 拉高PD2,触发74HC595,移位寄存
}
#ifdef ROLL
delay(0x100); // 决定滚屏时间长短的等待时间
LedUpdate(); // 显示到LED上
*(RP)PORTE_DATA = 0x0200>>Bit_i;
#endif
}
#ifndef ROLL
//delay(0x10000);
LedUpdate(); // 显示到LED上
#endif
}
}
void LedUpdate(void) // 74HC595锁存锁存输出,即led显示使能
{
*(RP)PORTG_DATA &= ~0x40;
*(RP)PORTG_DATA |= 0x20;
}
void delay(int cycle)
{
int j = 0;
for(j = 0; j < cycle; j++);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -