找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

各位大侠帮帮忙,小妹不知这程序哪里错了,就是调试不出

[复制链接]
admin 发表于 2012-8-24 10:55:27 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
ds1302时钟数据串口显示 这程序有点长,怎么写不下?
#ifndef __UART_H__
#define __UART_H__

void uart(void);
void send_ds1302(uchar buffer[],uchar length);
//void uart0_send(uchar buffer[],uint length);
#endif


#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#include<uart.h>

void uart(void)
{
SCON = 0X50;
PCON = 0X00;
TMOD = 0X20;

TH1 = 0XFD;
TL1 = 0XFD;
EA = 1;
TR1 = 1;
TI = 0;
RI = 0;
}

void send_ds1302(uchar buffer[],uchar length)
{
uint i;
for(i=0;i<length;i++)
{
while(buffer != '\0')
{
SBUF = buffer[i++];
while(!TI);
TI = 0;
}
}

}

#ifndef __DS1302_H__
#define __DS1302_H__

void write_byte(uchar dat);
uchar read_byte();
void write_ds1302(uchar add,uchar indat);
uchar read_ds1302(uchar add);
void read_nowtime(uchar add,uchar kn[],uchar n);
void delayus(uint z);
void init_1302();
#endif

#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#include<ds1302.h>
sbit rst = P3^6;
sbit io = P3^5;
sbit sclk = P3^4;
void delayus(uint z)
{
for(;z>0;z--)
_nop_();
_nop_();
_nop_();
}
void write_byte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
sclk=0;
delayus(8);

dat=dat>>1;
io=CY;

sclk=1;
delayus(8);
}
}
uchar read_byte()
{
uchar i,temp=0;
io=1;
for(i=0;i<8;i++)
{
sclk=0;
delayus(8);

temp=temp>>1;
if(io==1)

temp |= 0x80;

sclk=1;
delayus(8);
}

return temp;
}
void write_ds1302(uchar add,uchar indat)
{
rst=0;
delayus(8);
sclk=0;
delayus(8);
rst=1;
delayus(8);
write_byte(add);
write_byte(indat);
sclk=1;
delayus(8);
rst=0;
delayus(8);
}
uchar read_ds1302(uchar add)
{
uchar dat;
rst=0;
delayus(8);
sclk=0;
delayus(8);
rst=1;
delayus(8);
write_byte(add);
read_byte();
sclk=1;
delayus(8);
rst=0;
delayus(8);
return dat;
}
void read_nowtime(uchar add,uchar kn[],uchar n)
{
uchar i,k;
for(i=0;i<n;i++)
{
k=read_ds1302(add);
if(k!=0xff)
kn=k;
add+=2;

}
}
void init_1302()
{
rst=0;
delayus(8);
sclk=0;
delayus(8);
write_ds1302(0x8e,0x00); //写控制
write_ds1302(0x80,0x00);
write_ds1302(0x90,0xa6);
write_ds1302(0x8e,0x80);
}

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#include<ds1302.h>
#include<uart.h>

sbit k1=P0^0;
uchar init[]={0,0,0,0,0,0,0};
void main()
{
uart();
init_1302();
while(1)
{
if(!k1)
{ delayus(8);
if(!k1)
{
while(!k1)
read_nowtime(0x81,init,7);
send_ds1302(init,7);
}
}
}

}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-23 14:53 , Processed in 0.056324 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表