Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ds18b20 pic simulator ide problem

Status
Not open for further replies.

wchpikus

New Member
Hello!
I'm beginer in programming.
I have some expirence with electronic, but i have problem with software to my board.
PIC 16f874
clock 6Mhz

My connections:

Lcd:
E0-rs
E1-r/w
E2-e

D0 - D7 data to lcd

B1, B2, B3, B4 keys (poolup to vcc)
B7 background led
B6, B5 input (use to swicht)

C7- 1wire to ds18b20

Program:

Define CONF_WORD = 0x3f72
Define CLOCK_FREQUENCY = 6
AllDigital

Define LCD_BITS = 8
Define LCD_DREG = PORTD
Define LCD_DBIT = 0
Define LCD_RSREG = PORTE
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTE
Define LCD_RWBIT = 1
Define LCD_EREG = PORTE
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
Define 1WIRE_REG = PORTC
Define 1WIRE_BIT = 7

Dim templowbyte As Byte
Dim temphighbyte As Byte
Dim finish As Bit
Dim temp As Byte
Dim sign As Byte
Dim temp2 As Byte


Symbol led = PORTB.7
Symbol key1 = PORTB.0
Symbol key2 = PORTB.1
Symbol key3 = PORTB.2
Symbol key4 = PORTB.3

Lcdinit

TRISB = %00001111 ''''''''''''''''konfiguration Bport
led = 0

main:
''''''''''''''''''''''''''''''''''''''''''''main info
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "plytka testowa"
Lcdcmdout LcdLine2Home
Lcdout "klawisze 1,2,3"


If key1 = 0 Then
Goto klawisz1
Endif
If key2 = 0 Then
Goto klawisz2
Endif
If key3 = 0 Then
Goto klawisz3
Endif
If key4 = 0 Then
Goto temperatura
Endif

WaitMs 100

Goto main
'''''''''''''''''''''''''''''''''''''''''''''''''''''ds 1820 (i don't have code here)

''''''''''''''''''''''''''''''''''''''''''''''''''''

temperatura:
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "temperatura"
Lcdcmdout LcdLine2Home
Lcdout #temp
WaitMs 3
Goto main
'''''''''''''''''''''''''''''''''''''''''''''''''''
koniec
'''''''''''''''''''''''''''''''''''''''''''''''''''key1
klawisz1:
led = 1
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "Klawisz 1"
Lcdcmdout LcdLine2Home
Lcdout "led on"
led = 1
WaitMs 1
Goto main
''''''''''''''''''''''''''''''''''''''''''''''''''key1
'''''''''''''''''''''''''''''''''''''''''''''''''''key2
klawisz2:
led = 0
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "Klawisz 2"
Lcdcmdout LcdLine2Home
Lcdout "led off"
WaitMs 1
Goto main
''''''''''''''''''''''''''''''''''''''''''''''''key2

klawisz3:'''''''''''''''''''''''''''''''''''''''''''''test key3 to read tem from ds (not working)
ADCON1 = 7
1wireInit
1wireSendByte 0xfe, 0x40, 0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00
WaitMs 120
1wireSendByte 0x55, 0x10, 0x31, 0xc5, 0xc8, 0x00, 0x00, 0x00, 0xf4, 0x44

loop:
1wireGetBit finish
WaitMs 25
If finish = 0 Then
Goto loop

1wireSendByte 0x55, 0x10, 0x31, 0xc5, 0xc8, 0x00, 0x00, 0x00, 0xf4, 0xbe

If sign > 0 Then
Lcdout "-"
temp = 255 - temp
temp = temp + 1
Endif

loop:
DS18S20Start
WaitMs 1
DS18S20ReadT temp, sign

temp2 = temp * (1 / 100)
temp = temp2 / 2
Lcdout #temp
If temp2 = 1 Then
Lcdout ".5"
Else
Lcdout ".0"
Endif
Endif

WaitMs 5



Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "temperatura"
Lcdcmdout LcdLine2Home
Lcdout #sign,
Lcdout #temp2

If key1 = 0 Then
Goto main
Endif

Goto klawisz3
'''''''''''''''''''''''''''''''''''''''''''''''''key3


I found some code but it's no working:

loop:
DS18S20Start
WaitMs 1000
DS18S20ReadT temp, sign
Lcdcmdout LcdClear
If sign > 0 Then
Lcdout "-"
temp = 255 - temp
temp = temp + 1
Endif
temp2 = temp.0
temp = temp / 2
Lcdout #temp
If temp2 = 1 Then
Lcdout ".5"
Else
Lcdout ".0"
Endif
WaitMs 500
Goto loop

Could someone help me to start this device?
Regards
WCHPikus
WCHPikus@wp.pl
 
The DS18s220 code under your key 3 has no chance of working. Swap out with the code listed at the bottom of your post. Better yet, skip the button thing for now and just concentrate on getting the temp code working first.

You may want to try moving your one wire pin to another port pin.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top