⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo1.c

📁 PCF8563,AT24C02驱动程序
💻 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"      			//数学函数
#include "absacc.h"    			//绝对地址访问
#include "intrins.h"   			//内部函数

#include "AT24C02.h"
#include "AT24C02.C"

sbit SDA_DISP=P0^1;
sbit SCL_DISP=P0^0;
//#define NOP   _nop_ () 
#define LED0  0x40 //预定义数码管
#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;            
     }

}
//显示函数
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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -