欢迎来金海湾博客
Arthur912

https://blog.jinbay.com/Arthur912/  复制链接收藏

Arthur912个人头像
Arthur912
博客日历
«November 2024»
12
3456789
10111213141516
17181920212223
24252627282930
博客自定义分类
5/28/2009 8:17:00 PM [语言学习] 分享

分享





 
实验程序1:按S2键,让P1.0口发光管亮
#include     头文件
sbit d1=P1^0;         位声明
sbit key1=P3^4;       声明键盘输入口
void main()           主函数开始
{
       P3=0xff;                   让P3口熄灭
       while(1)                    进入大循环
              {
                     if (key1==0)        如果P3.4口变为低电平
                            d1=0;          P1.0口灯亮
                     else                否则
                            d1=1;          灯灭
              }
}
实验程序2:  按S2键,让数码管第一位按一次按键加1,在0~9之间循环
#include              头文件
#define uint unsigned int   
#define uchar unsigned char       宏定义
sbit d1=P1^0;                   位声明
sbit key1=P3^4;                 按键声明
sbit dula=P2^6;                  段选声明
sbit wela=P2^7;                 位选声明
uchar code table[]={             数组
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};
uchar num;                     定义变量num
void delay(uint z)                延时子程序
{
       uint x,y;
       for(x=z;x>0;x--)
              for(y=110;y>0;y--);      
}
 
void main()                     主函数
{
       wela=1;                    位选开
       P0=0xfe;                   让六位数码管第一位亮
       wela=0;                    位选锁存
 
       P3=0xff;                   关闭P3口
       while(1)                     开始大循环
              {
                     if (key1==0)              如果按键按下
                            {
                                   delay(10);            延时消除按键抖动
                                   if(key1==0)           然后确认按键按下
                                   {
                                          d1=0;              发光管亮
                                          num++;             变量num加1
                                          if(num==10)         
                                                 num=0;         当num加到10时,num返回0
                                   }
                                   while(!key1);            当按键按下时,KEY1的值等于0,!KEY1=1  当按键按下时不退出循环,一旦松手KEY的值=1,!1的值等于0 跳出循环
                            }
                           
                     else                              否则
                            d1=1;                       发光管灯灭
                            dula=1;                      段选开
                            P0=table[num];                让第一位显示num变量对应的数组的数
                            dula=0;                       段锁存
              }
}
 


实验程序3:矩阵键盘按键在六位数码管上显示相应数字
#include                      头文件
#define uint unsigned int                 
#define uchar unsigned char              宏定义
 
sbit key1=P3^4;                       
sbit dula=P2^6;                         段选
sbit wela=P2^7;                         位选
uchar code table[]={                     数组
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0
};
uchar num,temp;                     变量 num temp 声明
void delay(uint z)                     延时子程序
{
       uint x,y;
       for(x=z;x>0;x--)
              for(y=110;y>0;y--);      
}
 
void main()                         主函数
{
       dula=1;                       
       P0=0;
       dula=0;
       wela=1;
       P0=0xc0;
       wela=0;                       一开始让段选位选关闭
       while(1)                       开始矩阵键盘扫描
              {
                     P3=0xfe;                     首先给P3口送11111110
                     temp=P3;                     把11111110的值赋给temp
                     temp=temp&0xf0;              再让11111110“与”11110000   如果这个值等于11110000说明没有按键被按下  数码管上什么都不显示
                     while(temp!=0xf0)              如果与的值不等于11110000说明有按键被按下了 进入while循环
                            {
                                   delay(5);                进入循环后先延时一会消除抖动
                                   temp=P3;                这时把按下的P3值送给TEMP 确认按下。比如说按下的是第一个键, P3为11101110
                                   temp=temp&0xf0;         11101110与11110000 等于11100000
                                   while(temp!=0xf0)          因为temp的值不等于11110000了 所以进入while循环
                                   {
                                          temp=P3;              把11100000送给P3口
 
                     switch(temp)                       进入switch case语句
                            {
                                   case 0xee:num=1;           如果是11101110 说明是按键1
                                          break;
                                   case 0xde:num=2;           如果是11011110 说明是按键2
                                          break;
                                   case 0xbe:num=3;           如果是10111110 说明是按键3
                                          break;
                                   case 0x7e:num=4;           如果是01111110 说明是按键4
                                          break;
                            }
                            while(temp!=0xf0)               松手检测   
                            {
                                   temp=P3;
                                   temp=temp&0xf0;
                            }
 
                           
                            dula=1;
                            P0=table[num-1];
                            dula=0;                        显示
                            }
                            }
                     P3=0xfd;                           扫描第二行
                     temp=P3;
                     temp=temp&0xf0;
                     while(temp!=0xf0)
                            {
                                   delay(5);
                                   temp=P3;
                                   temp=temp&0xf0;
                                   while(temp!=0xf0)
                                   {
                                          temp=P3;
 
                     switch(temp)
                            {
                                   case 0xed:num=5;
                                          break;
                                   case 0xdd:num=6;
                                          break;
                                   case 0xbd:num=7;
                                          break;
                                   case 0x7d:num=8;
                                          break;
                            }
                            while(temp!=0xf0)
                            {
                                   temp=P3;
                                   temp=temp&0xf0;
                            }
                           
                            dula=1;
                            P0=table[num-1];
                            dula=0;
                            }
                            }
                     P3=0xfb;                         扫描第三行
                     temp=P3;
                     temp=temp&0xf0;
                     while(temp!=0xf0)
                            {
                                   delay(5);
                                   temp=P3;
                                   temp=temp&0xf0;
                                   while(temp!=0xf0)
                                   {
                                          temp=P3;
 
                     switch(temp)
                            {
                                   case 0xeb:num=9;
                                          break;
                                   case 0xdb:num=10;
                                          break;
                                   case 0xbb:num=11;
                                          break;
                                   case 0x7b:num=12;
                                          break;
                            }
                            while(temp!=0xf0)
                            {
                                   temp=P3;
                                   temp=temp&0xf0;
                            }
                           
                            dula=1;
                            P0=table[num-1];
                            dula=0;
                            }
                            }
                     P3=0xf7;                              扫描第四行
                     temp=P3;
                     temp=temp&0xf0;
                     while(temp!=0xf0)
                            {
                                   delay(5);
                                   temp=P3;
                                   temp=temp&0xf0;
                                   while(temp!=0xf0)
                                   {
                                          temp=P3;
 
                     switch(temp)
                            {
                                   case 0xe7:num=13;
                                          break;
                                   case 0xd7:num=14;
                                          break;
                                   case 0xb7:num=15;
                                          break;
                                   case 0x77:num=16;
                                          break;
                            }
                            while(temp!=0xf0)
                            {
                                   temp=P3;
                                   temp=temp&0xf0;
                            }
                           
                            dula=1;
                            P0=table[num-1];
                            dula=0;
                            }
                            }
             
              }
 
}
 
[图片摘自郭天翔视频教程]
 阅读全文>>

评论

分享 分享

对话:

我要刊登广告
我要刊登广告
5/28/2009 10:24:00 PM [] 分享

分享

一到夏天女性就穿超短迷你裙配吊带背心,白嫩的肌肤让人看了总有点想触摸的感觉。但是如果一身黝黑的皮肤,就算是穿得再漂亮也有点大煞风景。所以最重要的就是如何让肌肤美白才是关键。 1、蔬菜汁美白:</STRONG>将青椒、大黄瓜、四分之一苦瓜、西洋芹、青苹果等打成美容蔬菜汁来喝,这样的蔬菜汁里头有足够的维他命 C,对于美白非常有效。
2、中医美白方法:</STRONG>
     </STRONG> 材料:白芷、甘草、核仁、当归、绿豆粉、檀香等分研末。
  用法:先将脸洗干净,用适量的水加蜂蜜,牛奶及1/4颗的蛋白,适量调敷于全脸(当然眼及嘴不可敷),待干后再清水洗净即可。一星期1~2次(不要太多次,皮肤会受不了),可用于青春痘、黑班、雀斑,同样也可缩小鼻旁的毛细孔,用过的人都觉的不错,皮肤变白嫩,又便宜。
3、牛奶美白方法:</STRONG>准备一小杯鲜奶,(夏天的时候,也可以把鲜奶到放到冰箱里,敷上凉凉的,会更舒服)。用蒸气蒸脸,将化妆棉吸满鲜奶,敷在脸上十五分钟左右,取下,用清水将脸上的牛奶洗净。长期坚持,可以使肤色白净均匀。
4、芦荟护肤:</STRONG>准备三指宽二指长的面带斑点的芦荟叶去

阅读(85)评论(0)

5/28/2009 2:05:00 PM [旅游天下] 分享

分享

这一段时间堆积了很多让自己厌恶的情绪,尝试了各种方式都没能办摆脱。每天下班回家都把自己耗到精疲力尽了才去睡,也只有这样才能让我脑袋一粘到枕头就可以睡着。
    哪有那么多烦心的事儿啊!不过是自己给自己找麻烦罢了...
不想了,再看看我的马尔代夫吧~~真的很想去!真想马上收拾好行囊,明天一早就动身!
    ...我承认自己不是一个敢想就敢做的人,有太多放不下...不过想一想还是可以嘛!!!起码可以让心情明朗一些:)
  
    已经开始幻想了...被夕阳映红的海水泛着层层涟漪,我躺在柔软的沙滩上,CD机播放着轻柔的音乐,海风随着音乐起舞...惬意~~~

 
   


<embed ALLOWSCRIPTACCESS="samedomain" SRC="http://hzfsu.com/sound.mp3" TYPE="audio/mpeg" LOOP="true" AUTOSTART="true" WIDTH="200" HEIGHT="50">

阅读(115)评论(0)

© 2024 Jinbay.com All rights reserved. 版权所有金海湾。 未经许可,不得转载。