第一天,根據郭天祥老師留下的作業,分別用位操作和總線操作兩種方法完成以下題目:
1.熟練建立KEIL工程;
2點亮第一個發光管
3.點亮最後一個發光管
4.點亮1,3,5,7
5.點2,4,5,6
6.嘗試讓第一個發光管閃爍
7.嘗試設計出流水燈的程序
對於6,7我採用延時燈滅亮,不然看不到燈閃爍,因爲太快了
位操作程序如下:
//the bit operation
#include<reg52.h>
sbit D0=P1^0;
sbit D1=P1^1;
sbit D2=P1^2;
sbit D3=P1^3;
sbit D4=P1^4;
sbit D5=P1^5;
sbit D6=P1^6;
sbit D7=P1^7;
void main()
{
/*
D0=0; //bright the first light;
*/
/*
D7=0; //bright the last light
*/
/*
D0=0;D2=0;D4=0;D6=0;
*/
/*
D1=0;D3=0;D4=0;D5=0;
*/
//the D0 could light every 500ms
/*
unsigned int i,j,k;
while(1)
{
D0=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D0=1;
}
*/
//turnover the light
unsigned char i,j,k;
while(1)
{
D0=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D0=1;
D1=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D1=1;
D2=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D2=1;
D3=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D3=1;
D4=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D4=1;
D5=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D5=1;
D6=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D6=1;
D7=0;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
D7=1;
}
}
//還不會調函數
總線操作:
#include<reg52.h>
void main()
{
/*
P1=0XFE;//bright the first light;
*/
/*
P1=0X7F;//brignt the last light;
*/
/*
P1=0XAA;//bright the 1,3,5,7
*/
/*
P1=0XC5;//bright the 2,4,5,6
*/
unsigned char i,j,k;
/*while(1){
P1=0XFE;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
*/
while(1)
{
P1=0XFE;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
P1=0XFD;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
P1=0XFB;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
P1=0XF7;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
P1=0XEF;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
P1=0XDF;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
P1=0XBF;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
P1=0X7F;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--)
P1=0XFF;
}
}
花了一點時間,加!