Osawa_Odessa
Banned
- Joined
- Dec 31, 2012
- Messages
- 168
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,298
- Activity points
- 0
Hello, could anyone help me with the circuit and program bellow.
I want to use HS1101 to measure humidity using 16F877A in CCS. Here is the circuit I have built as in datasheet of HS1101.
Is the circuit look OK to you? I think it is ok but I am not sure if there is something wrong with it.
And here is the program I have used to measure humidity:
And here is hs1101.c
I have tried to changed the cap-var to change frequency and therefore change humidity but it always display humidity 0%.
Could you tell me what I am wrong? Your help is greatly appreciated!
I want to use HS1101 to measure humidity using 16F877A in CCS. Here is the circuit I have built as in datasheet of HS1101.
Is the circuit look OK to you? I think it is ok but I am not sure if there is something wrong with it.
And here is the program I have used to measure humidity:
Code:
#include "main.h"
#include "var.h"
#include "lcd16x2/lcd16x2.c"
#include "hs1101/hs1101.c"
#INT_RTCC
void ngat_timer0(void)
{
disable_interrupts(GLOBAL);
set_timer0(5);
count++;
if(count==100)
{
frequency=get_timer1();
set_timer1(0);
count=0;
enable_display=1;
}
enable_interrupts(GLOBAL);
}
void main()
{
uint8_t str[20],humi;
DDRB=0xfe;
DDRD=0x00;
DDRE=0x00;
LCD_Init();
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
sprintf(str,"Test");
LCD_Puts(str);
delay_ms(40);
set_timer0(5);
set_timer1(0);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(TRUE)
{
if(enable_display)
{
humi=HS1101_GetHumi(frequency);
enable_display=0;
sprintf(str,"Do Am:%3u",humi);
LCD_Gotoxy(0,1);
LCD_Puts(str);
LCD_PutChar('%');
}
}
}
Code:
/**
******************************************************************************
* Ten Tep : hs1101.c
* Tac Gia : Nguyen Quy Nhat
* Cong Ty : MinhHaGroup
* Website : BanLinhKien.Vn
* Phien Ban : V1.0.0
* Ngay : 31-07-2012
* Tom Tat : Dinh nghia ham do do am HS1101, khai bao bang tra.
*
*
******************************************************************************
* Chu Y :
******************************************************************************
**/
#include "hs1101.h"
const uint16_t HS1101_Table[101]={
8109,8090,8070,8051,8033,8015,7997,7979,7961,7944,
7927,7910,7894,7878,7862,7846,7830,7815,7799,7784,
7769,7755,7740,7726,7711,7697,7683,7669,7655,7641,
7628,7614,7600,7587,7574,7560,7547,7534,7521,7507,
7494,7481,7468,7455,7442,7429,7416,7403,7390,7377,
7364,7350,7337,7324,7311,7298,7284,7271,7257,7244,
7230,7216,7203,7189,7175,7161,7147,7132,7118,7103,
7089,7074,7059,7045,7029,7014,6999,6984,6968,6952,
6936,6920,6904,6888,6872,6855,6838,6821,6804,6787,
6770,6752,6735,6717,6699,6680,6662,6644,6625,6606,
6587};
/*******************************************************************************
Noi Dung : Doc gia tri do am.
Tham Bien : frequency: tan so do duoc tu bo dao dong NE555 ket hop HS1101.
Tra Ve : Gia tri do am do duoc tu HS1101.
********************************************************************************/
uint8_t HS1101_GetHumi(uint16_t frequency)
{
uint8_t i;
for(i=0;i<101;i++)
{
if((frequency+25)>HS1101_Table[i])return i;
}
return 100;
}
/******************************KET THUC FILE******************************
______________________________NGUYEN QUY NHAT______________________________*/
Could you tell me what I am wrong? Your help is greatly appreciated!