如何在Arm developer suite下读懂Led C语言
时间:10-02
整理:3721RD
点击:
最近接收任务,要读懂在Arm developer suite程序中 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 <string.h>
U8 SEGMENT[16] = { (U8)(sect2 + sect3 + sect4 + sect5 + sect6 + sect7), //0
(U8)(sect5 + sect6), //1
(U8)(sect1 + sect3 + sect4 + sect6 + sect7), //2
(U8)(sect1 + sect4 + sect5 + sect6 + sect7), //3
(U8)(sect1 + sect2 + sect5 + sect6), //4
(U8)(sect1 + sect2 + sect4 + sect5 + sect7), //5
(U8)(sect1 + sect2 + sect3 + sect4 + sect5 + sect7), //6
(U8)(sect5 + sect6 + sect7), //7
(U8)(sect1 + sect2 + sect3 + sect4 + sect5 + sect6 + sect7), //8
(U8)(sect2 + sect3 + sect4 + sect5 + sect6 + sect7), //9
(U8)(sect1 + sect2 + sect3 + sect5 + sect6 + sect7), //a
(U8)(sect1 + sect2 + sect3 + sect4 + sect5), //b
(U8)(sect2 + sect3 + sect4 + sect7), //c
(U8)(sect1 + sect3 + sect4 + sect5 + sect6), //d
(U8)(sect1 + sect2 + sect3 + sect4 + sect7), //e
(U8)(sect1 + sect2 + sect3 + sect7) //f
};
U8 prochip[8] = { 0xce, 0x60, 0x6e, 0x9c, 0xfc, 0xee, 0xce }; // prochip LOGO
U8 display[8] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; // 实验中显示的数据(0-0xf)
//U8 display[8] = {0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08}; // 实验中显示的数据(0-0xf)
#define ROLL; // 是否以滚屏方式显示: no define: 不滚屏
// define: 滚屏方式
int main(void)
{
char *s1,*s2,*s3;
s1="There is no LED on GE00\n";
s2="Error in Led lab!\n";
s3="Succeeded in Led lab!\n";
#ifdef GE00
DBG_Printf(s1);
return;
#else
if(E_OK != ModuleLed())
DBG_Printf("Error in Led lab!\n");
//PRINT(s2);
else //PRINT(s3);
DBG_Printf("Succeeded in Led lab!\n");
#endif
while(1);
return E_OK;
}
STATUS ModuleLed(void)
{
/* system initialized */
system_init(); // 系统初始化
/* GPIO initialized */
GPIO_Init();
/* led lab body */
// LedOut(prochip,5); // 在LED上显示“PROCHIP〉的logo
LedDisPlay(display); // 显示用户设定的内容
return E_OK;
}
void LedDisPlay(U8 data[])
{
U8* SegData;
Hex2Seg(data, SegData); // 十六进制数字翻译成7段译码值
LedOut(SegData, 10); // 在led上显示
}
void GPIO_Init()
{
*(RP)PORTD_SEL = 0x7; // 设定GPIO口 PD0/1/2 为通用口
*(RP)PORTD_DIR = 0x0; // 设定GPIO口 PD0/1/2 为数据输出
}
void Hex2Seg (U8 hexdata[], U8 * p)
{
int i;
for (i=0;i<8;i++)
{
*p++ = SEGMENT[hexdata[i]]; // 将要显示的数值,通过查找7段译码表翻译成码值
}
}
void LedOut(U8 data[], U32 times)
{
int Segment_i,Bit_i,i;
U8 Segment_Data;
U8 tempData;
for(i = 0; i < times; i++)
{
for (Bit_i = 0; Bit_i < 8 ;Bit_i++) // 依次串行导入八个led的显示内容
{
Segment_Data=*(data + Bit_i); // 获得一个led显示的码值
for (Segment_i = 0; Segment_i < 8; Segment_i++) // 将7段译码值依次串行输入到GPIO口中
{
tempData=(Segment_Data>>Segment_i) & 0x1; // 得到一段发光管的译码值
*(RP)PORTD_DATA = tempData; // 写入74HC595的输入端,同时拉低PD3
//delay(0x200000);
tempData |= 0x04;
*(RP)PORTD_DATA = tempData; // 拉高PD3,触发74HC595,移位寄存
//delay(0x200000);
}
#ifdef ROLL
LedUpdate(); // 显示到LED上
delay(0x100000); // 决定滚屏时间长短的等待时间
#endif
}
#ifndef ROLL
LedUpdate(); // 显示到LED上
#endif
}
}
void LedUpdate(void) // 74HC595锁存锁存输出,即led显示使能
{
*(RP)PORTD_DATA |= 0x2;
}
void delay(int cycle)
{
int j = 0;
for(j = 0; j < cycle; j++);
return;
}
以下是相应的源程序:
*************************************************************************************
* 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 <string.h>
U8 SEGMENT[16] = { (U8)(sect2 + sect3 + sect4 + sect5 + sect6 + sect7), //0
(U8)(sect5 + sect6), //1
(U8)(sect1 + sect3 + sect4 + sect6 + sect7), //2
(U8)(sect1 + sect4 + sect5 + sect6 + sect7), //3
(U8)(sect1 + sect2 + sect5 + sect6), //4
(U8)(sect1 + sect2 + sect4 + sect5 + sect7), //5
(U8)(sect1 + sect2 + sect3 + sect4 + sect5 + sect7), //6
(U8)(sect5 + sect6 + sect7), //7
(U8)(sect1 + sect2 + sect3 + sect4 + sect5 + sect6 + sect7), //8
(U8)(sect2 + sect3 + sect4 + sect5 + sect6 + sect7), //9
(U8)(sect1 + sect2 + sect3 + sect5 + sect6 + sect7), //a
(U8)(sect1 + sect2 + sect3 + sect4 + sect5), //b
(U8)(sect2 + sect3 + sect4 + sect7), //c
(U8)(sect1 + sect3 + sect4 + sect5 + sect6), //d
(U8)(sect1 + sect2 + sect3 + sect4 + sect7), //e
(U8)(sect1 + sect2 + sect3 + sect7) //f
};
U8 prochip[8] = { 0xce, 0x60, 0x6e, 0x9c, 0xfc, 0xee, 0xce }; // prochip LOGO
U8 display[8] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; // 实验中显示的数据(0-0xf)
//U8 display[8] = {0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08}; // 实验中显示的数据(0-0xf)
#define ROLL; // 是否以滚屏方式显示: no define: 不滚屏
// define: 滚屏方式
int main(void)
{
char *s1,*s2,*s3;
s1="There is no LED on GE00\n";
s2="Error in Led lab!\n";
s3="Succeeded in Led lab!\n";
#ifdef GE00
DBG_Printf(s1);
return;
#else
if(E_OK != ModuleLed())
DBG_Printf("Error in Led lab!\n");
//PRINT(s2);
else //PRINT(s3);
DBG_Printf("Succeeded in Led lab!\n");
#endif
while(1);
return E_OK;
}
STATUS ModuleLed(void)
{
/* system initialized */
system_init(); // 系统初始化
/* GPIO initialized */
GPIO_Init();
/* led lab body */
// LedOut(prochip,5); // 在LED上显示“PROCHIP〉的logo
LedDisPlay(display); // 显示用户设定的内容
return E_OK;
}
void LedDisPlay(U8 data[])
{
U8* SegData;
Hex2Seg(data, SegData); // 十六进制数字翻译成7段译码值
LedOut(SegData, 10); // 在led上显示
}
void GPIO_Init()
{
*(RP)PORTD_SEL = 0x7; // 设定GPIO口 PD0/1/2 为通用口
*(RP)PORTD_DIR = 0x0; // 设定GPIO口 PD0/1/2 为数据输出
}
void Hex2Seg (U8 hexdata[], U8 * p)
{
int i;
for (i=0;i<8;i++)
{
*p++ = SEGMENT[hexdata[i]]; // 将要显示的数值,通过查找7段译码表翻译成码值
}
}
void LedOut(U8 data[], U32 times)
{
int Segment_i,Bit_i,i;
U8 Segment_Data;
U8 tempData;
for(i = 0; i < times; i++)
{
for (Bit_i = 0; Bit_i < 8 ;Bit_i++) // 依次串行导入八个led的显示内容
{
Segment_Data=*(data + Bit_i); // 获得一个led显示的码值
for (Segment_i = 0; Segment_i < 8; Segment_i++) // 将7段译码值依次串行输入到GPIO口中
{
tempData=(Segment_Data>>Segment_i) & 0x1; // 得到一段发光管的译码值
*(RP)PORTD_DATA = tempData; // 写入74HC595的输入端,同时拉低PD3
//delay(0x200000);
tempData |= 0x04;
*(RP)PORTD_DATA = tempData; // 拉高PD3,触发74HC595,移位寄存
//delay(0x200000);
}
#ifdef ROLL
LedUpdate(); // 显示到LED上
delay(0x100000); // 决定滚屏时间长短的等待时间
#endif
}
#ifndef ROLL
LedUpdate(); // 显示到LED上
#endif
}
}
void LedUpdate(void) // 74HC595锁存锁存输出,即led显示使能
{
*(RP)PORTD_DATA |= 0x2;
}
void delay(int cycle)
{
int j = 0;
for(j = 0; j < cycle; j++);
return;
}
先把硬件原理图接口搞懂,再来看程序