CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SHT11 Code Debugging

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
YASAS



Joined: 29 Jun 2004
Posts: 5

View user's profile Send private message

SHT11 Code Debugging
PostPosted: Mon Jul 05, 2004 4:21 am     Reply with quote

I need to read data from SHT11 throw computer parallel port(I'm connect to sensor pin2 to parallel port pin15,14 and sensor pin3 to parallel port pin16.

I downloaded freeBSD program If I convert it into windows platform
but it did not work (Output "Device timed Out !!")

does someone con debug my coding?

Regards,

yasas

My coding----


#include <stdio.h>
#include <dos.h>



#define DeviceTimeout 20
#define ReadTimeout 200


//pin 14 : out: bit 2 of 0x37a
//pin 15 : in: bit 8 of 0x379
//pin 16 : out: bit 4 of 0x37a

int Data(int Level) {
outportb(0x37a,(inportb(0x37a)&4) + 2*(!Level));
delay(1*1000);

return (inportb(0x379)&8)==8;
}

void Clock(int Level) {
outportb(0x37a,(inportb(0x37a)&2) + 4*Level);
delay(1*1000);
}



void Bus_Init(void) {
int Cnt;

//Initiate bus
outportb(0x378,0xff);
Data(1);
Clock(1);

//Connection reset sequence
for (Cnt=0; Cnt<9; Cnt++) {
Clock(0);
Clock(1);
}
}



int Bus_Read(unsigned char Command) {
int Cnt;
int Time;
int ReadData;


//Transmission start
Clock(1);
Data(0);
Clock(0);
Clock(1);
Data(1);
Clock(0);


//Send address & command
for (Cnt=0; Cnt<8; Cnt++) {
if (((Command >> (7-Cnt))&1)==1)
Data(1);
else
Data(0);

Clock(1);
Clock(0);
}


//ACK
Data(1);
Clock(1);

Time=0;
while ((Data(1)==1) && (Time++<DeviceTimeout))
delay(1*1000);
if (Time>DeviceTimeout)
printf("Device timed out!!!%c\n",0x07);

Clock(0);


//Wait for the SHT11 to get it's data ready
Time=0;
while ((Data(1)==1) && (Time++<ReadTimeout))
delay(1*1000);
if (Time>ReadTimeout)
printf("Measurement timed out!!!%c\n",0x07);


//Now clock 2 bytes of data in...
ReadData=0;

for (Cnt=0; Cnt<8; Cnt++) {
Clock(1);

ReadData<<=1;
if (Data(1)==1)
ReadData|=1;

Clock(0);
}
//ACK
Data(0);
Clock(1);
Clock(0);
Data(1);

for (Cnt=0; Cnt<8; Cnt++) {
Clock(1);

ReadData<<=1;
if (Data(1)==1)
ReadData|=1;

Clock(0);
}
//!ACK
Data(1);
Clock(1);
Clock(0);

return ReadData;
}



#define Cmd_ReadTemp 0x03
#define Cmd_ReadHum 0x05




int main(void)
{
//FILE *IO = fopen("G:\progport\a\io.txt","r");

int TempData;
int HumData;

float Temp;
float Humidity;


/*if (IO==NULL) {
printf("could not open /dev/io");
}*/


Bus_Init();

TempData=Bus_Read(Cmd_ReadTemp);
HumData=Bus_Read(Cmd_ReadHum);

Temp=TempData*0.01-40.0;
Humidity=-4.0 + 0.0405*HumData - 2.8*HumData*HumData/1000000;

printf("temp: %.2f hum: %.2f\n",Temp,Humidity);

//fclose(IO);


return 0;
}
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: SHT11 Code Debugging
PostPosted: Wed Jul 07, 2004 6:51 pm     Reply with quote

YASAS wrote:
I need to read data from SHT11 throw computer parallel port(I'm connect to sensor pin2 to parallel port pin15,14 and sensor pin3 to parallel port pin16.


your answer is here:
http://www.ccsinfo.com/forum/viewtopic.php?p=29127&highlight=#29127

and here
http://216.239.51.99/

jds-pic
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Jul 07, 2004 7:19 pm     Reply with quote

Your code is converted from FreeBSD, it contains a lot of outportb() and inportb() function calls. I'm not sure if Windows allows reading/writing to the ports directly. You program will probably work fine under pure DOS.

The best way for you to solve this is probably to search Google for a parallel port OCX for Visual basic. I know a couple of free ones are around. They should allow you to read/write the port easily.

http://rspsoftware.clic3.net/rspppc.htm
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group