標題:
單片機通過24c02設(shè)置產(chǎn)品的使用次數(shù)
[打印本頁]
作者:
張plan
時間:
2017-11-21 14:17
標題:
單片機通過24c02設(shè)置產(chǎn)品的使用次數(shù)
設(shè)計產(chǎn)品的使用次數(shù)+程序源碼
0.png
(7.98 KB, 下載次數(shù): 76)
下載附件
2017-11-21 22:35 上傳
單片機源程序如下:
#include <reg52.H>
/****************************************************************************
24C08 讀寫驅(qū)動程序 開始
*****************************************************************************/
#include <reg52.H>
#include <stdio.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
sbit scl=P3^3; //24c02 SCL
sbit sda=P3^4; //24c02 SDA
uchar x24c02_read(uchar address); //從24c02的地址address中讀取一個字節(jié)數(shù)據(jù)
void x24c02_write(uchar address,uchar info);
//向24c02的address地址中寫入一字節(jié)數(shù)據(jù)info
void x24c02_init(); //24c02初始化子程序
void delay1(uchar x);
void flash();
void x24c01_init();
void start();
void stop();
void writex(uchar j);
uchar readx();
void clock();
void delay1(uchar x)
{
uint i;
for(i=0;i<x;i++);
}
void flash()
{}
void x24c02_init()
{
scl=1; flash(); sda=1; flash();
}
void start()
{
sda=1; flash(); scl=1; flash(); sda=0; flash(); scl=0; flash();
}
void stop()
{
sda=0; flash(); scl=1; flash(); sda=1; flash();
}
void writex(uchar j)
{
uchar i,temp;
temp=j;
for (i=0;i<8;i++){
temp=temp<<1; scl=0; flash(); sda=CY; flash(); scl=1; flash();
}
scl=0; flash(); sda=1; flash();
}
uchar readx()
{
uchar i,j,k=0;
scl=0; flash(); sda=1;
for (i=0;i<8;i++){
flash(); scl=1; flash();
if (sda==1) j=1;
else j=0;
k=(k<<1)|j; scl=0;
}
flash(); return(k);
}
void clock()
{
uchar i=0;
scl=1; flash();
while ((sda==1)&&(i<255))i++;
scl=0; flash();
}
uchar x24c02_read(uchar address)
{
uchar i;
start(); writex(0xa0);
clock(); writex(address);
clock(); start();
writex(0xa1); clock();
i=readx(); stop();
delay1(10);
return(i);
}
void x24c02_write(uchar address,uchar info)
{
EA=0;
start(); writex(0xa0);
clock(); writex(address);
clock(); writex(info);
clock(); stop();
EA=1;
delay1(50);
}
//====================================================================//
main()
{
signed char sec; //定義數(shù)值
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
設(shè)置產(chǎn)品的使用次數(shù).zip
(231.69 KB, 下載次數(shù): 18)
2017-11-21 14:15 上傳
點擊文件名下載附件
程序源碼
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1