欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
我想問問這個proteus里 單片機和點陣為什么要這樣接線?
[打印本頁]
作者:
gf818099
時間:
2019-12-18 00:27
標題:
我想問問這個proteus里 單片機和點陣為什么要這樣接線?
51hei截圖20191218002557.png
(66.29 KB, 下載次數: 21)
下載附件
2019-12-18 00:27 上傳
程序#include<reg51.h> //51系列單片機頭文件
#defineuchar unsigned char //宏定義
#defineuint unsigned int //宏定義
/******************************************************
基礎定義
*******************************************************/
ucharm=0,n=0;
ucharo,p,d;
uchartime=0;
ucharcode table[]={0x01,0x04,0x08,0x02,0x40,0x10,0x80,0x20};
/******************************************************
數碼顯示數據定義
*******************************************************/
ucharcode taba[]={
0xff,0xef,0xef,0xef,0xab,0xc7,0xef,0xff}; //編碼定義↓
ucharcode tab1[]={
0xff,0xef,0xcf,0xef,0xef,0xef,0xef,0xc7}; //編碼定義1
ucharcode tab2[]={
0xff,0xc7,0xbb,0xfb,0xf7,0xcf,0xbf,0x83}; //編碼定義2
ucharcode tab3[]={
0xff,0xc7,0xbb,0xfb,0xe7,0xfb,0xbb,0xc7}; //編碼定義3
ucharcode tab4[]={
0xff,0xf7,0xe7,0xd7,0xb7,0xb7,0x83,0xf7}; //編碼定義4
ucharcode tab5[]={
0xff,0x83,0xbf,0x87,0xfb,0xfb,0xbb,0xc7}; //編碼定義5
ucharcode tab6[]={
0xff,0xe7,0xdf,0xbf,0x87,0xbb,0xbb,0xc7}; //編碼定義6
/******************************************************
延時
*******************************************************/
voiddelay(uchar n) //延時子函數
{
uchar i,j;
for(i=n;i>0;i--)
{
for(j=255;j>0;j--);
}
}
/********************************************************************
* 名稱 : ucharChangeFor(uchar dat)
* 功能 : 交換一個字節位的位置,用于數碼管顯示
* 輸入 : 需要改變的數
* 輸出 : 改變后的數
***********************************************************************/
#defineLED_a 4 //數碼管段選的a段接在段選IO口的第0位
#defineLED_b 3
#defineLED_c 1
#defineLED_d 5
#defineLED_e 0
#defineLED_f 6
#defineLED_g 7
#defineLED_dp 2
ucharChangeFor(uchar dat)
{
uchar temp=0;
if(dat&0x01) //判斷數據的第一位是否為1
temp|=0x01<<LED_a;//如果為1,放到控制數碼管a段的位置
if(dat&0x02)
temp|=0x01<<LED_b;
if(dat&0x04)
temp|=0x01<<LED_c;
if(dat&0x08)
temp|=0x01<<LED_d;
if(dat&0x10)
temp|=0x01<<LED_e;
if(dat&0x20)
temp|=0x01<<LED_f;
if(dat&0x40)
temp|=0x01<<LED_g;
if(dat&0x80)
temp|=0x01<<LED_dp;
return temp;
}
/******************************************************
T/C0中斷服務程序入口
*******************************************************/
timer0()interrupt 1 using 1 //定時器0工作方式1
{
TH0 = (65536-50000)/256; //賦初值
TL0 = (65536-50000)%256; //賦初值
if(o>p)//if語句一般處理兩個分支,處理多個分支用if-else-if結構
{
d=1;
}
else if(o<p)
{
d=2;
}
else
{
d=0;
}
time++;
if(time==1)
{
n=~(1<<(p+1));
}
else if(time==5)
{
if(d==0)
{
n=~(1<<(p+1));
}
else if(d==1)
{
p++;
n=0xfe;
}
else if(d==2)
{
p--;
n=0xfd;
}
}
else if(time==20)
{
time = 0;
}
}
/******************************************************
定時器T/C0初始化
*******************************************************/
voidcom_initialize(void) //定時器初始化
{
TMOD = 0x01;//設定定時器0為工作方式1
TH0 = (65536-50000)/256; //裝初值
TL0 = (65536-50000)%256; //裝初值
EA = 1; //開總中斷
ET0 = 1; //開定時器0中斷
TR0 = 1; //啟動定時器0
}
/******************************************************
主函數
*******************************************************/
voidmain() //主函數
{
uchar i=0,j=0,k=0;
uchar tmp=0;
uchar om=0;
d=0;
m=0;
o=1;
p=1;
n=0xff;
com_initialize();
while(1) //主循環
{
for(i=0;i<8;i++)
{
P1=0xff;
P0=table[ i]; //[ i]刷新
if(++k==50) //延時
{
k=0;
}
m=P1; //記錄按鍵
if(m != 0xff && d==0&& m!=om)
{
om=m;
switch(m) //開關語句
{
case 0xfb:
tmp=1;break;
case 0xf7:
tmp=2;break;
case 0xef:
tmp=3;break;
case0xdf:
tmp=4;break;
case 0xbf:
tmp=5;break;
case 0x7f:
tmp=6;break;
default:
tmp=o;break;
}
if(o!=tmp)
{
p=o;
o=tmp;
time=0;
}
n=m;
}
if(n==0xfe) //識別按鍵值
{
if(k==0)
j=++j%8;
P2=ChangeFor(taba[7-(i+j)%8]);
}
else if(n==0xfd)
{
if(k==0)
{
if(j>0)
j--;
else
j=7;
}
P2=ChangeFor(taba[(i+j)%8]);
}
else if(n==0xfb)
{
P2=ChangeFor(tab1[ i]);
}
elseif(n==0xf7)
{
P2=ChangeFor(tab2[ i]);
}
else if(n==0xef)
{
P2=ChangeFor(tab3[ i]);
}
else if(n==0xdf)
{
P2=ChangeFor(tab4[ i]);
}
else if(n==0xbf)
{
P2=ChangeFor(tab5[ i]);
}
else if(n==0x7f)
{
P2=ChangeFor(tab6[ i]);
}
delay(5);
}
}
}
復制代碼
作者:
man1234567
時間:
2019-12-19 21:56
16點陣8橫8縱,分別各接一P口(0-7)。話說電燈2根線并成一根會省線,但燈不會亮。
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1