📄 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 "def.h"
U16 prochip[4] = {0xce40,0x6040,0x6e40,0x9c40};
U16 Num[10];
U16 LedNum[10];
U16 Numdot[10];
// ê?·?ò?1??á·?ê???ê?£o no define: 2?1??á
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 ?aí¨ó??ú
*(RP)PORTG_DIR = 0x0; // éè?¨GPIO?ú PD0/1/2 ?aêy?Yê?3?
*(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??ò????μòà′?′?DDê?è?μ?GPIO?ú?D
{
tempData=(Segment_Data<<(15-Segment_i)) & 0x8000; // μ?μ?ò???·¢1a1üμ?ò????μ
*(RP)PORTG_DATA = ((U8)(tempData>>8)) | portgdatatemp ; // D′è?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++) // òà′?′?DDμ?è?4??ledμ???ê??úèY
{
Segment_Data=*(data + Bit_i); // ??μ?ò???led??ê?μ????μ
for (Segment_i = 0; Segment_i < 16; Segment_i++) // ??7??ò????μòà′?′?DDê?è?μ?GPIO?ú?D
{
tempData=(Segment_Data<<(15-Segment_i)) & 0x8000; // μ?μ?ò???·¢1a1üμ?ò????μ
*(RP)PORTG_DATA = (U8)(tempData>>8); // D′è?74HC595μ?ê?è???£?í?ê±à-μíPD2
*(RP)PORTG_DATA = 0x40; // à-??PD2£?′¥·¢74HC595£?ò?????′?
}
#ifdef ROLL
delayl(0x100); // ???¨1??áê±??3¤?ìμ?μè′yê±??
LedUpdate(); // ??ê?μ?LEDé?
*(RP)PORTE_DATA = 0x0200>>Bit_i;
#endif
}
#ifndef ROLL
//delay(0x10000);
LedUpdate(); // ??ê?μ?LEDé?
#endif
}
}
void LedUpdate(void) // 74HC595??′???′?ê?3?£??′led??ê?ê1?ü
{
*(RP)PORTG_DATA &= ~0x40;
*(RP)PORTG_DATA |= 0x20;
}
void delayl(int cycle)
{
int j = 0;
for(j = 0; j < cycle; j++);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -