ARM7—LPC2124—NXP-Philips实践
1)
运行流水灯,运行数码管,
A)硬件操作
同前
B)
同前
C)
//双数码管共阴极--数组
#include
typedef unsigned int uint;
uint const ShuMa_TAB[]={0xC0C0,0xF9F9,0xA4A4,0xB0B0,0x9999,0x9292,0x8282,
0xF8F8,0x8080,0x9090,0x8888,0x8383,0xC6C6,0x0A1A1,0x8686,0x8E8E};//共阳极码
void delay (void)// 软件延时函数delay()
{
unsigned volatile long i,j;
for(i=0;i<60000;i++);
for(j=0;j<9;j++);
}
int main(void)
{
PINSEL0 = 0; //用PINSEL0设置引脚为GPIO ;PINSEL1设置?
IO0DIR = 0x00FFFF;//将P0.0~P0.15设置为输出,阳极硬件--高电平,阴极硬件可取反;DIR?
IO0SET = 0x00FFFF; //将P0.0~P0.15置1,也就是让led灭
while (1)
{
unsigned volatile long n;
for(n=0;n<16;n++)
{
IO0SET =~ShuMa_TAB[n];
delay();
IO0CLR =~ShuMa_TAB[n];
delay();
}
}
}
程序说明:
从LED组灯的流水—扫描,可以过渡到数码管的显示与控制问题。比较TAB[]=中的数字码就明白了。也体现了数组和循环在程序编写中的作用和好处。
D)
========================================================
|
二进制 |
十进制 |
二进制 |
十进制 |
二进制 |
十六进制 |
二进制 |
十六进制 |
|
0000 |
0 |
0100 |
4 |
1000 |
8 |
1100 |
C |
|
0001 |
1 |
0101 |
5 |
1001 |
9 |
1101 |
D |
|
0010 |
2 |
0110 |
6 |
1010 |
A |
1110 |
E |
|
0011 |
3 |
0111 |
7 |
1011 |
B |
1111 |
F |
--------个数码管------------
//4数码管共阴极表--数组
#include
typedef unsigned int uint;
uint const ZIFU_TAB[]={0xC0C0,0xF9F9,0xA4A4,0xB0B0,0x9999,0x9292,0x8282,
0xF8F8,0x8080,0x9090,0x8888,0x8383,0xC6C6,0x0A1A1,0x8686,0x8E8E};//共阳极码
uint const ZIFU_TAB1[]={0xC0C0000,0xF9F90000,0xA4A40000,0xB0B00000,
0x99990000, 0x92920000,0x82820000,0xF8F80000,0x80800000,0x90900000,
0x88880000,0x83830000,0xC6C60000,0x0A1A10000,0x86860000,0x8E8E0000};//共阳极码
void delay (void)// 软件延时函数delay()
{
unsigned volatile long i,j;
for(i=0;i<60000;i++);
for(j=0;j<600;j++);
}
int main(void)
{
PINSEL0 = 0; //用PINSEL0设置引脚为GPIO ;
IO0DIR = 0x0FFFFFFFF;//将P0.0~P0.30设置为输出,阳极硬件--高电平,阴极硬件不能取反;
IO0SET = 0x0FFFFFFFF; //将P0.0~P0.30置1,也就是让led灭
IODIR1 = 0x0FFFF0000;//将P1.16~P1.30设置为输出,阳极硬件--高电平,阴极硬件不能取反;
IOSET1 = 0x0FFFF0000;
while (1)
{
unsigned volatile long n,m;
for(n=0;n<16;n++)
{
IO0SET =~ZIFU_TAB[n];
delay();
IO0CLR =~ZIFU_TAB[n];
delay();
for(m=0;m<16;m++)
{
IOSET1 =~ZIFU_TAB1[m];
delay();
IOCLR1 =~ZIFU_TAB1[m];
delay();
}
}
}
}
------------------------------------------------



