|
我的12864 是调的别人的库 没问题 这是程序 结果总是显示1279不变 拔掉1820 竟然还是显示同样的数字,请大侠帮帮忙 谢谢
#include<avr/io.h>
#include<util/delay.h>
#include "st7920.h"
#define uchar unsigned char
#define uint unsigned int
unsigned char table0[7]={""};
const char DIP_NUM[16]={"0123456789.C"};
#define ds_dat (PINA & 0x01)
#define ddr_dat 0
#define out_dat DDRA|=(1<<ddr_dat) //set output
#define in_dat DDRA&=~(1<<ddr_dat) //set input
#define set_dat PORTA|=(1<<ddr_dat) //set dat
#define clr_dat PORTA&=~(1<<ddr_dat) //clr dat
//unsigned char wmh,wml;
unsigned int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10; //
long int t; //temperature
unsigned char a[9];
unsigned char b[9];
//***********************************
//功能:初始化
//说明:
void init_1820(void)
{
out_dat; //set output
set_dat; //set dat
clr_dat; //clr dat
_delay_us(480); //wait 480us
set_dat; //set dat
in_dat; //set input
_delay_us(60); //wait 15~60us
while(!ds_dat);
out_dat; //set output
set_dat; //set dat
_delay_us(140); //wait 60~240us
}
//***********************************
//功能:写一BYTE
//说明:
void write_1820(unsigned char x)
{
unsigned char m;
for(m=0;m<8;m++)
{
clr_dat;
if(x&(1<<m))
set_dat;
else
{clr_dat; }
_delay_us(60);
set_dat;
}
set_dat;
}
//***********************************
//功能:读一BYTE
//说明:
unsigned char read_1820()
{
unsigned char temp,k,n;
temp=0;
for(n=0;n<8;n++)
{
clr_dat ;
set_dat;
in_dat;
k=ds_dat; //read data
if(k)
temp|=(1<<n);
else
{temp&=~(1<<n); }
_delay_us(40);
out_dat;
}
return (temp);
}
//***********************************
//功能:得到数据
//说明:
void gettemp()
{
t=0;
// init_1820(); //resert
// write_1820(0xcc); //overlook 64bit address
init_1820(); //resert
write_1820(0xcc); //overlook 64bit address
write_1820(0x44); //start convert
_delay_ms(800);
init_1820(); //resert
write_1820(0xcc); // overlook 64bit address
write_1820(0xbe); //read memory
a1=read_1820(); //read temp low
//a2=read_1820(); //read temp hign
a3=read_1820(); //read th
a4=read_1820(); //read tl
a5=read_1820(); //read config
a6=read_1820(); //read reserved
a7=read_1820(); //.............
a8=read_1820(); //..............
a9=read_1820(); //read crc
// if(a2&0xf8) {a10='-';a1=~a1+1;a2=~a2;} // temperature sign
// else a10='+';
a2=0x07&a2;
t=t+a2;
t=t<<8;
t=t+a1;
t=t*625;
a[0]=t/1000000; //100
a[1]=t%1000000/100000; //10
a[2]=t/10000%100%10; //1
a[4]=t%10000/1000; //.1
a[5]=t%1000/100; //0.01
a[6]=t%100/10; //0.001
a[7]=t%10; //0.0001
a[3]=a[0]*100+a[1]*10+a[2]; //int part
a[8]=a[4]*1000+a[5]*100+a[6]*10+a[7]; //decimal fraction
table0[0]=DIP_NUM[ a[0]];
table0[1]=DIP_NUM[ a[1]];
table0[2]=DIP_NUM[ a[2]];
table0[3]=DIP_NUM[ 10];
table0[4]=DIP_NUM[ a[4]];
table0[5]=DIP_NUM[11];
}
/*void get_id()
{ unsigned char ii=0;
init_1820(); //resert
write_1820(0x33);
for(ii;ii<8;ii++)
{b[ii]=read_1820();
}
}
*/
unsigned char text[]={"少说话多做事"};
int main()
{
//LCD_ClearRam();
//LCD_DisplayCLR();
LCD_Init();
LCD_DisplayChinese(0,0,text);
// while(1);
//unsigned char d=4;
// unsigned char c=5;
// unsigned char b=6;
//table2[3]=4;
// LCD_Init();
/// LCD_ClearRam();
// LCD_DisplayCLR();
// LCD_DisplayChinese(0,0,text1);
//LCD_DisplayCLR();
//Init_DS18B20();
while(1)
{
//_delay_ms(10);
//LCD_DisplayStrings_WithAddress(0x80,text);
// init_1820() ;
// get_temp();
gettemp();
//_delay_ms(50);
LCD_Init();
LCD_ClearRam();
LCD_DisplayCLR();
LCD_DisplayChinese(0,2,text);
_delay_ms(500);
LCD_DisplayChinese(0,1,table0);
//LCD_DisplayStrings_WithAddress(0x80,table2);
// LCD_DisplayStrings_WithAddress(0x80,"table2[d]");
// LCD_DisplayChinese(0,2,table0);
_delay_ms(500);
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|