|
為了能讓沒有黑幣的也可以使用,我就直接貼代碼,有問題可以相互學(xué)習(xí),一同進步QQ:2074561566
1234.png (346.91 KB, 下載次數(shù): 98)
下載附件
2019-7-29 15:08 上傳
#include "reg52.h"
#include "intrins.h"//包含_nop_()指令頭文件
//引腳定義
sbit CLK=P1^0; //定義CLK
sbit DIO=P1^1; //定義DIO
#define nop _nop_();_nop_();_nop_();_nop_();_nop_();//宏定義
/********************定義數(shù)據(jù)*************************/
unsigned char code CODE[10]= {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,}; //共陽數(shù)碼管0~9字型碼
unsigned char code TAB[10]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}; //數(shù)碼管不顯示
/********************延時函數(shù),延時nms******************/
void delay_nms(unsigned int n) {
unsigned int i;
while(n--)
for(i=0; i<550; i++);
}
/********************Start函數(shù)*************************/
void I2CStart() {
DIO=1;
CLK=1;
nop;
DIO=1;
nop;
DIO=0;
nop;
CLK=0;
}
/********************Stop函數(shù)*************************/
void I2CStop() {
CLK=0;
nop;
nop;
DIO=0;
nop;
nop;
CLK=1;
nop;
nop;
nop;
DIO=1;
nop;
CLK=0;
DIO=0;
}
/***************發(fā)送8bit數(shù)據(jù),從低位開始**************/
void I2CWritebyte(unsigned char oneByte) {
unsigned char i;
for(i=0; i<8; i++) {
CLK=0;
if(oneByte&0x01) {
DIO=1;
} else {
DIO=0;
}
nop;
CLK=1;
oneByte=oneByte>>1;
}
//8位數(shù)據(jù)傳送完
CLK=0;//判斷芯片發(fā)過來的ACK應(yīng)答信號
nop;
while(DIO==1);
nop;
CLK=1;
nop;
}
/************顯示函數(shù),地址自加一************/
void disp0(unsigned char *p) {
unsigned char i;
I2CStart();
I2CWritebyte(0x40); //數(shù)據(jù)命令設(shè)置:地址自動加1,寫數(shù)據(jù)到顯示寄存器
I2CStop();
I2CStart();
I2CWritebyte(0xc0); //地址命令設(shè)置:初始地址為00H
for(i=0; i<4; i++) { //發(fā)送4字節(jié)數(shù)據(jù)到顯存
I2CWritebyte(*p);
p++;
}
I2CStop();
I2CStart();
I2CWritebyte(0x8C); //顯示控制命令:開顯示,脈沖寬度為11/16.
I2CStop();
}
/************顯示函數(shù),固定地址寫數(shù)據(jù)************/
void Seg_Shows(unsigned char add, unsigned char value) {
I2CStart();
I2CWritebyte(0x44); //數(shù)據(jù)命令設(shè)置:固定地址,寫數(shù)據(jù)到顯示寄存器
I2CStop();
I2CStart();
I2CWritebyte(add);//地址命令設(shè)置:寫入add對應(yīng)地址
I2CWritebyte(CODE[value]);//給add地址寫數(shù)據(jù)
I2CStop();
I2CStart();
I2CWritebyte(0x8C);//顯示控制命令:開顯示,脈沖寬度為11/16.
I2CStop();
}
//主函數(shù)代碼
void main(void){
while(1){
Seg_Shows(0xc0,1);
Seg_Shows(0xc1,2);
Seg_Shows(0xc2,3);
Seg_Shows(0xc3,4);
}
}
數(shù)碼管接線圖
www點titanmec點com/index.php/product/view/id/300.html
數(shù)據(jù)線時鐘線接P1^1 P1^0
本程序在89C52/12C5AXXX單片機上測試通過
|
評分
-
查看全部評分
|