|
|
View previous topic :: View next topic |
Author |
Message |
nortepic
Joined: 18 Apr 2016 Posts: 1
|
DHT22... code |
Posted: Mon Apr 18, 2016 8:16 pm |
|
|
i have this code for dht22...it is bases in the libraries of another forum
it is not very good, but i'm new in ccs, so i think that for this time it's ok :P
#include <18f4550.h> //PIC utilizado
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=20M)
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48M)
#build (reset=0x1000,interrupt=0x1008)
#org 0x0000,0x0FFF{}
//#use i2c(Master,slow,sda=PIN_A4,scl=PIN_A5)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "dht22.c"
#include <LCD420.c>
void main(){
int16 lux;
float dhthum, dthtemp;
setup_adc_ports(AN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
EXT_INT_EDGE(H_TO_L);
lcd_init();
lcd_putc("\fDHT22");
delay_ms(500);
printf(lcd_putc,"\f");
lcd_gotoxy(1,1);
printf(lcd_putc,"Control");
lcd_gotoxy(1,2);
printf(lcd_putc,"Temperatura");
lcd_gotoxy(1,3);
printf(lcd_putc,"y Humedad");
dht_init();
delay_ms(300);
lcd_putc("\f");
while(true){
set_adc_channel(0);
delay_ms(1);
lux=read_adc();
delay_ms(10);
leer_dht22(dhthum, dthtemp);
delay_ms(10);
delay_ms(1);
lcd_gotoxy(1,1);
printf(lcd_putc,"Temp= %f %cC", dthtemp,223);
lcd_gotoxy(1,4);
printf(lcd_putc,"Hum= %f %%",dhthum);
delay_ms(2000);
Last edited by nortepic on Tue Apr 19, 2016 9:27 pm; edited 1 time in total |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Apr 19, 2016 4:52 am |
|
|
Hi,
What *could* be the problem, or what *is* the problem? Big difference!
The fact is that nobody here wants to debug a Proteus project - it's pointless!
So, you should try the DHT-22 driver found in the code library and see if that works! In general, you shouldn't be re-inventing the wheel anyway! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Apr 19, 2016 5:30 am |
|
|
John's tag line is the TRUTH!!
Us older guys KNOW Proteus is busted, full of errors and faulty DRCs and never, ever use it.
Basic trouble shooting says
1) get the PIC 'up and running' the 1Hz LED program. This MUST be done to confirm hardware is valid,fuses are correct and the PIC clock is running at the correct speed.
2) get the PIC to say 'Hello PC !' or 'Hello LCD !'. Again this MUST be done to confirm hardware and software is correct.
3) read the device datasheet, look at the timing diagrams ! 'Play computer' and confirm every step, every timing(delay) is proper for THAT device.
4) copy old program to a new one, make change to the new one NOT the old one,then compile the new one, test. and repeat. It's too easy to make 2 or 3 'small' changes to working code and then nothing works ! Yes, you can end up with 30-40-77 versions BUT who cares? Delete all but the last 3 when your project is complete. Add comments to every line of code,they cost nothing but will tell you 1 day - 1 month from now WHAT it does.
5) re: drivers. NEVER edit an original driver! Copy as 'my_driver.c' and use it, modify if needed. Again,editing a working driver can be disasterous, costing you a LOT of time trying to decide why it doesnt't work...it did before !
Jay |
|
|
|
|
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
|