Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

DS2760 with ATMega8535 and LCD 2X16

Status
Not open for further replies.

dimas_lilik

Full Member level 2
Joined
Aug 13, 2007
Messages
125
Helped
13
Reputation
26
Reaction score
11
Trophy points
1,298
Location
Indonesia
Activity points
1,952
atmega8535 untuk lcd

Dear everybody..
Can help me ?
I want to display with LCD 2 X 16
please Help me

/***************************
DS2760 Interfacing
****************************/
#include <stdio.h> // printf(), uchar, uint, ....
#include <reg51.h> // CPU's interals
#include "1wire.h" // 1-wire device lib

/************************
Port Declaration
*************************/
// DS2760 port declaration at 1wire.c

/*******************************************************************
T-type (Copper/Constantan) thermocouple data (0C reference)
Author : Compiled by Parallax
Updated : 19 JAN 2004
********************************************************************/
const uint Cnv_table[401]=
{
/*T000*/ 0, 39, 78, 117, 156, 195, 234, 273, 312, 352,
/*T010*/ 391, 431, 470, 510, 549, 589, 629, 669, 709, 749,
/*T020*/ 790, 830, 870, 911, 951, 992, 1032, 1074, 1114, 1155,
/*T030*/ 1196, 1238, 1279, 1320, 1362, 1403, 1445, 1486, 1528, 1570,
/*T040*/ 1612, 1654, 1696, 1738, 1780, 1822, 1865, 1908, 1950, 1993,
/*T050*/ 2036, 2079, 2121, 2165, 2208, 2250, 2294, 2338, 2381, 2425,
/*T060*/ 2468, 2512, 2556, 2600, 2643, 2687, 2732, 2776, 2819, 2863,
/*T070*/ 2909, 2952, 2998, 3043, 3087, 3132, 3177, 3222, 3266, 3312,
/*T080*/ 3358, 3403, 3447, 3494, 3539, 3584, 3631, 3677, 3722, 3768,
/*T090*/ 3814, 3859, 3907, 3953, 3999, 4046, 4092, 4137, 4185, 4232,
/*T100*/ 4278, 4325, 4371, 4419, 4466, 4512, 4561, 4608, 4655, 4701,
/*T110*/ 4750, 4798, 4844, 4892, 4940, 4988, 5036, 5084, 5131, 5179,
/*T120*/ 5227, 5277, 5325, 5373, 5421, 5469, 5519, 5567, 5616, 5665,
/*T130*/ 5714, 5762, 5812, 5860, 5910, 5959, 6008, 6057, 6107, 6155,
/*T140*/ 6206, 6254, 6304, 6355, 6403, 6453, 6504, 6554, 6604, 6653,
/*T150*/ 6703, 6754, 6804, 6855, 6905, 6956, 7006, 7057, 7107, 7158,
/*T160*/ 7209, 7259, 7310, 7360, 7411, 7463, 7515, 7565, 7617, 7668,
/*T170*/ 7719, 7770, 7823, 7874, 7926, 7977, 8028, 8080, 8133, 8185,
/*T180*/ 8237, 8288, 8340, 8393, 8445, 8496, 8550, 8602, 8653, 8707,
/*T190*/ 8759, 8811, 8865, 8916, 8970, 9022, 9076, 9128, 9182, 9234,
/*T200*/ 9288, 9341, 9394, 9448, 9500, 9554, 9608, 9662, 9714, 9769,
/*T210*/ 9822, 9875, 9929, 9984, 10038, 10092, 10146, 10200, 10253, 10307,
/*T220*/ 10362, 10416, 10471, 10525, 10580, 10634, 10689, 10743, 10798, 10852,
/*T230*/ 10907, 10961, 11016, 11072, 11127, 11182, 11237, 11291, 11346, 11403,
/*T240*/ 11458, 11512, 11569, 11624, 11679, 11734, 11791, 11846, 11902, 11958,
/*T250*/ 12012, 12069, 12125, 12181, 12237, 12293, 12349, 12405, 12461, 12518,
/*T260*/ 12573, 12630, 12686, 12743, 12798, 12855, 12912, 12968, 13025, 13082,
/*T270*/ 13139, 13195, 13253, 13310, 13365, 13423, 13480, 13537, 13595, 13652,
/*T280*/ 13708, 13766, 13823, 13881, 13938, 13995, 14053, 14109, 14168, 14226,
/*T290*/ 14282, 14341, 14399, 14455, 14514, 14572, 14630, 14688, 14746, 14804,
/*T300*/ 14862, 14919, 14977, 15035, 15095, 15153, 15211, 15269, 15328, 15386,
/*T310*/ 15445, 15503, 15562, 15621, 15679, 15737, 15797, 15855, 15913, 15973,
/*T320*/ 16032, 16091, 16149, 16208, 16268, 16327, 16387, 16446, 16504, 16564,
/*T330*/ 16623, 16682, 16742, 16801, 16861, 16920, 16980, 17039, 17100, 17158,
/*T340*/ 17219, 17278, 17338, 17399, 17458, 17518, 17577, 17638, 17698, 17759,
/*T350*/ 17818, 17879, 17939, 17998, 18059, 18120, 18179, 18240, 18301, 18362,
/*T360*/ 18422, 18483, 18542, 18603, 18664, 18725, 18786, 18847, 18908, 18969,
/*T370*/ 19030, 19091, 19152, 19213, 19274, 19335, 19396, 19457, 19518, 19579,
/*T380*/ 19641, 19702, 19763, 19824, 19885, 19946, 20009, 20070, 20132, 20193,
/*T390*/ 20255, 20317, 20378, 20440, 20501, 20563, 20625, 20687, 20748, 20810,
/*T400*/ 20872
};

/*************************************************
Constants & Global variable
**************************************************/
const uchar readnet=0x33; // read OW net address
const uchar skipnet=0xcc; // skip OW net address
const uchar rdreg=0x69; // read register

/*near uchar idx; // loop counter (4-bit)
near uchar type; // device type (4-bit)
near uchar char_; // display byte/char
near uint vIn; // in millivolts */
near uint tmpCJ; // device temp in C
near uint tCuV; // thermocouple millivolts
near uint sign; // TC sign bit
near uint cjComp; // temp compensation
near uint tempC; // temp in Celsius
near uint tblLo, tblHi, eePntr; // table pointers
near uint testVal; // test value from table
near uchar error; // 1 = out of range (1-bit)
//near uchar store8; // 8-bit buffer

/**********************************************
Subroutines
***********************************************/

/* Inisialisasi UART @ 9600 bps, 8-N-1 */
void init232(void)
{
TMOD=(TMOD&0x0F)|0x20; // Timer 1 Mode 2 (Auto reload)
SCON=0x52; // Serial Mode 1 (8-bit UART), REN=1 (Receiver Enable)
// TI=1 (Transmit buffer empty)
PCON=PCON&0x7F; // SMOD=0 (Double baud rate disable)
TH1=0xFD; // 9600 bps (11,059 MHz)
ET1=0; // Disable Timer 1 interrupt
TR1=1; // Timer 1 Run
}

/* Reads current register to get TC voltage
-- each raw bit = 15.625 uV
-- tCuV in microvolts */
void Read_TC_Volts(void){
uchar buf;
uint buf16;
ow_reset(); // read current register
ow_writebyte(skipnet);
ow_writebyte(rdreg);
ow_writebyte(0x0e);
tCuV=ow_readbyte();
buf=ow_readbyte();
ow_reset();
tCuV<<=8;
tCuV+=buf;
sign=tCuV>>15; // save sign bit
tCuV>>=3; // correct alignment
if(sign==1){
tCuV|=0xf000; // pad 2's-compliment bits
tCuV=~tCuV; // tCuV= -tCuV
tCuV+=1;
}
/* tCuV*=156; // x 15.625 uV
tCuV/=10; */
/* tCuV x 15.625 uV == (tCuV x 15) + (tCuV x 0.625) */
buf16=tCuV*15; // tCuV x 15
tCuV*=5; // tCuV x 0.625 == (tCuV x 5) / 8
tCuV>>=3;
tCuV+=buf16;
}

/* Reads cold junction (device) temperature
-- each raw bit = 0.125 degrees C
-- returns tmpCJ in whole degrees C */
void Read_CJ_Temp(void){
uchar buf;
ow_reset();
ow_writebyte(skipnet);
ow_writebyte(rdreg);
ow_writebyte(0x18);
tmpCJ=ow_readbyte();
buf=ow_readbyte();
ow_reset();
tmpCJ<<=8;
tmpCJ+=buf;
if(tmpCJ>=0x8000){ // check sign
tmpCJ=0; // disallow negative
}else{
tmpCJ>>=8; // >> 5 x 0.125 (>> 3)
}
}

/* Search currently selected TC table for nearest entry
-- uses modified binary algorithm to find cjComp
-- high end of search set before calling (tblHi)
-- successful search sets tempC */
void TC_Lookup(void){
tblLo=0; // low entry of table
tempC=22; // default to room temp
testVal=Cnv_table[tblHi]; // check max temp
if(cjComp>testVal){
error=1; // out of range
}else{
while(1){
eePntr=(tblLo+tblHi)/2; // midpoint of search span
testVal=Cnv_table[eePntr]; // read value from midpoint
if(cjComp==testVal){
goto exitTC; // found it!
}else{
if(cjComp<testVal){tblHi=eePntr;} // search lower half
else {tblLo=eePntr;} // search upper half
}
if((tblHi-tblLo)<2){ // span at minimum
eePntr=tblLo;
goto exitTC;
}
}
exitTC:
tempC=eePntr;
}
}


/*******************************************
MAIN: Start here!
********************************************/
void main(void){
uchar i;
uchar ID[8];

/* Inisialisasi UART */
init232();
/* Check_Device */
if(!ow_reset()){ // get serial number
printf("No Presence!\n");
goto exitMain;
}
ow_writebyte(readnet);
for(i=0;i<8;i++){
ID=ow_readbyte();
}
ow_reset();
printf("ID = ");
for(i=0;i<8;i++){
printf("%X",ID);
}
printf("\n");
if(ID[0]!=0x30){ // if not 0x30, wrong device
printf("Wrong 1-Wire device!\n");
goto exitMain;
}

/* Measure Temperature */
while(1){
error=0;
Read_TC_Volts(); // read Seebeck voltage
Read_CJ_Temp(); // read cold junction temp
cjComp=Cnv_table[tmpCJ]; // get compensation voltage
/* combine cjComp and tCuV */
if(sign==1){
/* TC below cold junction */
if(tCuV<cjComp){
cjComp-=tCuV;
}else{
cjComp=0; // limit to 0 C
}
}else{
/* TC above cold junction */
cjComp+=tCuV;
}
tblHi=400; // set high end of search
TC_Lookup(); // reverse lookup of table
if(error==0){
/* display tempC */
printf("Temp = %u C\n", tempC);
}else{
/* Out of Range */
printf("Out of range!\n");
goto exitMain;
}
ow_waitms(1000);
}
exitMain:
while(1){};
}

/* END */
 

Many Thank's for all.
now, I can program DS2760 with Atmega8535 and LCD 2X16

May be this useful to every body

Than's
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top