这个程序跳了一下午了,求高人指点
这个程序,调了很久不知道错在哪里了,希望大家找找,谢谢了,太谢谢打家了。/**************************************主模块******************************************/
#include "delay.h"
#include "read_write_init.h"
bitwrite=0;
uchar t=0;
uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void mian()
{
TMOD=0x01;
EA=1;
ET0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
scl=1;
sda=1;
t=read_add(6);
TR0=1;
while(1)
{
P0=table;
p27=0;
delayms(2);
p27=1;
P0=table;
p26=0;
delayms(2);
p26=1;
if(write==1) //判断计时器是否计时一秒
{
write=0; //清零
write_address(6,t);//在24c08的地址2中写入数据sec
}
if(k1==0)
{
delayms(10);
if(k1==0)
{
t=0;
}
}
}
}
void t0() interrupt 1
{
uchar i;
i++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(i>=20)
{
i=0;
t+=1;
write=1;
if(t>=100)
t=0;
}
}
/*****************************************************************/
#include"delay.h"
#include<intrins.h>
void start()//开始信号
{
sda=1;
scl=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
sda=0;
_nop_();_nop_();_nop_();_nop_();_nop_();
scl=0;
}
void stop()//终止信号
{
sda=0;
scl=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
sda=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
scl=0;
sda=0;
}
bit wait_nok()
{
bit ack_bit;
sda=1;
_nop_();_nop_();
scl=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
ack_bit=sda;
scl=0;
return ack_bit;
}
void write_byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
sda=(bit)(dat&0x80);
_nop_();
scl=1;
_nop_();_nop_();
scl=0;
dat<<=1;
}
}
uchar read_byte()
{
uchar i,k;
for(i=0;i<8;i++)
{
scl=1;
k<<=1;
k|=sda;
scl=0;
}
return (k);
}
void write_address(uchar add,uchar date)
{
start();
write_byte(0xa0);
wait_nok();
write_byte(add);
wait_nok();
write_byte(date);
wait_nok();
stop();
delayms(5);
}
uchar read_add(uchar add)
{
uchar m;
start();
write_byte(0xa0);
wait_nok();
write_byte(add);
wait_nok();
start();
write_byte(0xa1);
wait_nok();
m=read_byte();
stop();
return (m);
}
/**********************************************************************************/
#ifndef __READ_WRITE_INIT_H__
#define __READ_WRITE_INIT_H__
//void init();
uchar read_byte();
uchar read_add(uchar add);
void write_address(uchar add,uchar date);
#endif
/********************************************************************************/
#include "delay.h"
/*
void delay5us() //延迟5毫秒左右
{
;;
}
*/
void delayms(uchar a)
{
uchar k;
while(a--)
for(k=115;k>0;k--);
}
/*******************************************************************************/
#ifndef __DELAY_H__
#define __DELAY_H__
#include<reg52.h>
#define uchar unsigned char
sbit scl=P3^4;
sbit sda=P3^5;
sbit k1=P3^2;
sbit p27=P2^7;
sbit p26=P2^6;
//void delay5us();
void delayms(uchar a);
#endif 你做好说下 你想干什么 出的什么问题说下
这么一大段代码 估计没人看 典型的新手,你都不说问题在哪里,谁有功夫一行一行的给你看。
另外,程序是调的,不是跳的。 建议先把错别字改好了,“这个程序跳了一下午了,求高人指点 [复制链接]”,调试程序,跳改成”调“。 谢谢,一下午了,都懵了
才一下午就放弃?? 太弱了吧????!!!!
想当年我一个FatFS的程序折腾了一个月~ 注释这么少?
弄懂每一行代码的意思了吗?
页:
[1]