使用存储器映射扩展方式,要注意将J13的1,2脚短接!!!!!!!
要引入absacc.h头文件
通过XBYTE关键字来进行操作? XBYTE[0x8000]=0x00
0X8000:LED指示灯; 0Xa000:蜂鸣器与继电器 0Xc000:数码管位选 0Xe000:数码管段选
例程:
#include "reg52.h"
#include <absacc.h>
void delay(unsigned int n);
void selectHC(unsigned char n);
void ledRun();
void smgRun();
void Init()
{
selectHC(5);
P0=0x00;
}
sbit beer=P0^6;
void main()
{
Init();
while(1)
{
ledRun();
smgRun();
}
}
void delay(unsigned int n)
{
while(n--);
while(n--);
}
void selectHC(unsigned char n)
{
switch(n)
{
case 4: P2=(P2&0x1f)|0x80; break;
case 5: P2=(P2&0x1f)|0xa0; break;
case 6: P2=(P2&0x1f)|0xc0; break;
case 7: P2=(P2&0x1f)|0xe0; break;
}
}
void ledRun()
{
XBYTE[0x8000]=0xf0; //低四位亮
delay(60000);
delay(60000);
XBYTE[0x8000]=0x0f; //高四位亮
delay(60000);
delay(60000);
XBYTE[0x8000]=0xff; //全部熄灭
delay(60000);
delay(60000);
}
void smgRun()
{
unsigned char i;
for(i=0;i<8;i++)
{
XBYTE[0xc000]=0x01<<i; //位选
XBYTE[0xe000]=0x00; //段选
delay(60000);
delay(60000);
}
XBYTE[0xe000]=0xff;
delay(60000);
delay(60000);
}
|