?? demo1.c
字號:
#include <reg51.h> /* special function register declarations */
/* for the intended 8051 derivative */
#include <stdio.h> /* prototype declarations for I/O functions */
#include "math.h" //數(shù)學(xué)函數(shù)
#include "absacc.h" //絕對地址訪問
#include "intrins.h" //內(nèi)部函數(shù)
#include "AT24C02.h"
#include "AT24C02.C"
sbit SDA_DISP=P0^1;
sbit SCL_DISP=P0^0;
//#define NOP _nop_ ()
#define LED0 0x40 //預(yù)定義數(shù)碼管
#define LED1 0x41
#define LED2 0x42
#define LED3 0x43
#define LED4 0x44
#define LED5 0x45
#define LED6 0x46
#define LED7 0x47
unsigned char data led8 ;
void Delay_ms(unsigned char t);
void Shift(unsigned char Disp_date);
void Display(unsigned int Disp_count);
unsigned char code Dispbuf[]={0x11,0xD7,0x32,0x92,0xD4,0x98,0x18,0xD3,
0x10,0x90,0x50,0x1C,0x39,0x16,0x38,0x78,0xFF} ;//顯示代碼0~f
unsigned int count; //全局變量0~65536
unsigned char sendbyte[10];
unsigned char Recivebyte[10];
//at24c02 driver
/*******************/
/* main program */
/*******************/
main(){
//unsigned char data *P;
unsigned char tmp=0;
unsigned char i;
count=0;
for(i=0;i<10;i++)
{
sendbyte[i]=i+1;
Recivebyte[i]=0;
}
/*
while(1){
for(count=0;count<9999;count++){
Display(count);
Delay_ms(1000);
}
Delay_ms(1000);
count=0;
}
*/
Display(count);
Delay_ms(100);
/*
AT24C02_Write1Byte(0x04,0x08); // 向AT24C02的地址0x02寫入0xaa
Delay_ms(10);
tmp =AT24C02_Read1Byte(0x04);
count = (unsigned int )tmp;
*/
AT24C02_WriteNByte(0x08,sendbyte,8);
//for(i=0;i<6;i++)
//{
// AT24C02_Write1Byte(0x00+i,i);
//}
Delay_ms(100);
AT24C02_ReadNByte(0x08,Recivebyte,8);
//for(i=0;i<6;i++)
//{
// Recivebyte[i]=AT24C02_Read1Byte(0x00+i);
//}
for(;;)
{
for(i=0;i<8;i++)
{
count = Recivebyte[i];
Display(count);
Delay_ms(200);
Delay_ms(200);
}
}
}
void Delay_ms(unsigned char t)// ;延時10ms
{
unsigned char i;
unsigned int j;
for(i=0;i<t;i++){
j=210; //1ms
while(j--);
}
}
void Shift(unsigned char Disp_date){
unsigned char i,k;
for(i=0;i<8;i++){
k=Disp_date&0x80;
if(k==0x80) {SCL_DISP=0;SDA_DISP=1;SCL_DISP=1;}
else {SCL_DISP=0;SDA_DISP=0;SCL_DISP=1;}
Disp_date<<=1;
}
}
//顯示函數(shù)
void Display(unsigned int Disp_count)
{
unsigned char LedDate;
LedDate=Dispbuf[Disp_count%10]; //led0
Shift(LedDate);
LedDate=Dispbuf[(Disp_count/10)%10]; //led1
Shift(LedDate);
LedDate=Dispbuf[(Disp_count/100)%10]; //led2
Shift(LedDate);
LedDate=Dispbuf[Disp_count/1000]; //led3
Shift(LedDate);
LedDate=Dispbuf[0]; //led4
Shift(LedDate);
LedDate=Dispbuf[0]; //led5
Shift(LedDate);
LedDate=Dispbuf[0]; //led6
Shift(LedDate);
LedDate=Dispbuf[0]; //led7
Shift(LedDate);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -