人体红外感应程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/*#include

sbit in=P3^3;
void delay(unsigned long time)
{
unsigned long i,j;
for(i=0;ifor(j=0;j<19;j++)
{}
}
void main()
{
while(1)
{
if(in==1)
P1=0x00;
delay(1000);
P1=0xff;
}
}
*/


#include
void setCol(char n);
void setRow(char n);
void flush_Vram();

sbit led_D=P2^7;
sbit led_C=P2^6;
sbit led_B=P2^5;
sbit led_A=P2^4;
sbit in=P3^3;

sbit led_G=P2^3;
sbit led_DI=P2^2;
sbit led_CLK=P2^1;
sbit led_LAT=P2^0;

#define led_off() led_G=1
#define led_on() led_G=0

unsigned char code zim[]={
/*-- 文字: 请 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x02,0x42,0x33,0x00,0x00,0x22,0x2A,0x2A,0x2A,0xFE,0x2A,0x2A,0x2A,0x22,0x02,0x00,
0x00,0x00,0xFE,0x04,0x08,0x00,0xFF,0xA8,0xA8,0xA8,0xAA,0xA9,0xFE,0x00,0x00,0x00,

/*-- 文字: 勿 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x01,0x02,0x04,0x18,0xF0,0x11,0x1E,0x10,0x10,0x1F,0x10,0x10,0x10,0x1F,0x00,0x00,
0x00,0x08,0x10,0x21,0x42,0x84,0x08,0x10,0x60,0x80,0x02,0x01,0x02,0xFC,0x00,0x00,

/*-- 文字: 乱 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x04,0x04,0x24,0x24,0x7F,0xC4,0x44,0x04,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0x84,0x84,0x84,0xFE,0x00,0x00,0xFC,0x02,0x02,0x02,0x02,0x1E,0x00,

/*-- 文字: 丢 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x24,0x24,0x24,0x24,0x24,0x3F,0x44,0x44,0x44,0xC4,0x44,0x00,0x00,0x00,
0x40,0x40,0x42,0x47,0x4A,0x52,0x62,0xC2,0x42,0x42,0x4A,0x46,0x43,0x40,0x40,0x00,

/*-- 文字: 垃 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x04,0x04,0x04,0xFF,0x04,0x04,0x08,0x09,0x88,0x68,0x08,0x08,0x0B,0x08,0x00,0x00,
0x08,0x0C,0x08,0xF0,0x10,0x12,0x02,0x82,0x7A,0x02,0x0E,0x72,0x82,0x02,0x02,0x00,

/*-- 文字: 圾 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x04,0x04,0x04,0xFF,0x04,0x44,0x40,0x7F,0x40,0x40,0x46,0x5A,0x62,0x03,0x00,0x00,
0x10,0x18,0x10,0xE0,0x22,0x2C,0x71,0x81,0x62,0x14,0x08,0x14,0x62,0x81,0x01,0x00,


};
unsigned short vram[16]={0};
bit flush_led_flag=0;
bit flush_vram_flag=0;

void delay(unsigned long time)
{
unsigned long i,j;
for(i=0;ifor(j=0;j<19;j++)
{}
}


int main(){
char i;
TMOD=0x01;
TH0=0xFA;
TL0=0xCD;
TR0=1;
ET0=1;
EA=1;

while(1){
if(in==1)
/*P1=0x00;
delay(1000);
P1=0xff; */
{
if(flush_led_flag)
{
flush_led_flag=0;
led_off();
setRow(i);
setCol(i);
led_on();

i++;
i%=16;
}
if(flush_vram_flag){
flush_vram_flag=0;
flush_Vram();
}
else
{
TR0=1;
ET0=1;
EA=1;
flush_vram_flag=0;
//flush_led_flag=0;
}
}
}
}

void flush_Vram(){
char i,zs=0,neibucol;
static char col=0;
unsigned short dat;
zs=col/

16;
neibucol=col%16;
dat = zim[zs*32+neibucol];
dat <<= 8;
dat += zim[zs*32+neibucol+16];

//P1=dat;

for(i=15;i>=0;i--){
vram[i] <<= 1;
if(dat&0x0001)vram[i] |=0x0001;
dat >>=1;
}
col++;
col %=96;
}

void timer0()interrupt 1 using 1
{
static short count=0;
TH0=0xFA;
TL0=0xCD;

flush_led_flag=1;

count++;
if(count>=100){
count=0;
flush_vram_flag=1;
}
}

void setRow(char n){
switch(n){
case 0:led_D=0;led_C=0;led_B=0;led_A=0;break;
case 1:led_D=0;led_C=0;led_B=0;led_A=1;break;
case 2:led_D=0;led_C=0;led_B=1;led_A=0;break;
case 3:led_D=0;led_C=0;led_B=1;led_A=1;break;
case 4:led_D=0;led_C=1;led_B=0;led_A=0;break;
case 5:led_D=0;led_C=1;led_B=0;led_A=1;break;
case 6:led_D=0;led_C=1;led_B=1;led_A=0;break;
case 7:led_D=0;led_C=1;led_B=1;led_A=1;break;
case 8:led_D=1;led_C=0;led_B=0;led_A=0;break;
case 9:led_D=1;led_C=0;led_B=0;led_A=1;break;
case 10:led_D=1;led_C=0;led_B=1;led_A=0;break;
case 11:led_D=1;led_C=0;led_B=1;led_A=1;break;
case 12:led_D=1;led_C=1;led_B=0;led_A=0;break;
case 13:led_D=1;led_C=1;led_B=0;led_A=1;break;
case 14:led_D=1;led_C=1;led_B=1;led_A=0;break;
case 15:led_D=1;led_C=1;led_B=1;led_A=1;break;
}
}

void setCol(char n){
char i;
unsigned short dat;

led_LAT=0;

dat=~vram[n];
for(i=0;i<16;i++){
led_CLK=0;
led_DI=dat&0x0001;
led_CLK=1;
dat >>= 1;
}
led_LAT=1;
}

相关文档
最新文档