Napravio sam pločicu za Nokia LCD Termometar od Ivana Novakovića, Sve radi perfektno osim jedne male sitnice koja je meni početniku veliki problem .
Ovaj program je koliko sam ja skonto pisan za temperaturni senzor DS18B20 koji koristi 12 bita za očitavanje temperatute, a ja imam DS1820 koji radi sa 9 bita. Sad bi trebao prepraviti program da koristi 9 bita za očitavanje temperature. Da ne ispadne da se nimalo nisam potrudio, napisao sam u mikroC-u program koji radi bez problema ali je prevelik za ovaj pic zato sam odlučio iskorisitti kod od novkivića ali ne razumim baš picBasic pa ako netko može da mi objasni kako da mi ovo proradi.
Code: Select all
'****************************************************************
'* Name : Nokia LCD Termometar *
'* Author : Novakovic Ivica *
'* Notice : Copyright (c) 2004 [Elektronika Kifo] *
'* : All Rights Reserved *
'* Date : 9.10.2004 *
'* Version : 1.0 *
'* Notes : Pic12F629 , Nokia3310 Lcd & DS18B20 *
'* e-mail : ivica.novakovic@vz.t-com.hr *
'* url : http://fr*e-vz.t-com.hr/Ivica-Novakovic/ *
'****************************************************************
Define NO_CLRWDT 1
D_C var GPIO.0
rst var GPIO.1
DQ var GPIO.2
Mode var GPIO.3
SDIN var GPIO.4
SCK var GPIO.5
temperature Var Word
TempHigh var temperature.highbyte
count_remain Var Byte
count_per_c Var Byte
TempH var byte
TempL var byte
Bitovi var byte
Predznak var Bitovi.0
Skala var byte[4]
Minus var Byte
LcdReg var byte
x var byte
y var byte
z var byte
Offset var byte
Char var byte
a var byte
'-------------------------------------------------------------------------------
CMCON = 7
TrisIO = 0
GPIO = 0
'-------------------------------------------------------------------------------
DATA @0,$3E,$51,$49,$45,$3E,_ ';// 0 Podaci zapisani u EEPROM
$00,$42,$7F,$40,$00,_ ';// 1
$42,$61,$51,$49,$46,_ ';// 2
$21,$41,$45,$4B,$31,_ ';// 3
$18,$14,$12,$7F,$10,_ ';// 4
$27,$45,$45,$45,$39,_ ';// 5
$3C,$4A,$49,$49,$30,_ ';// 6
$01,$71,$09,$05,$03,_ ';// 7
$36,$49,$49,$49,$36,_ ';// 8
$06,$49,$49,$29,$1E,_ ';// 9
$08,$08,$3E,$08,$08,_ ';// +
$08,$08,$08,$08,$08,_ ';// -
$00,$60,$60,$00,$00 ';// .
data @65,$FF,$01,$01,$E1,$11,$89,$49,$49,$C9,$49,$09,$C9,$49,$49,$09,$09,_ 'prvi dio slike
$09,$09,$11,$E1,$01,$19,$19,$19,$F9,$F9,$F9,$19,$19,$19,$81,$C1,_
$E1,$21,$E1,$E1,$C1,$01,$E1,$E1,$E1,$41,$E1,$E1,$C1,$61,$E1,$E1,_
$C1,$01,$E1,$E1,$E1,$41,$E1,$E1,$C1,$01,$01,$01,$01,$01,$01
'-------------------------------------------------------------------------------
RST = 1
LcdReg = %00100001 'LCD Extended Commands.
call PrintCtrlLcd
LcdReg = %10101001 'Set LCD Vop (Contrast).
call PrintCtrlLcd
LcdReg = %00000110 'Set Temp coefficent.
call PrintCtrlLcd
LcdReg = %00010011 'LCD bias mode 1:48.
call PrintCtrlLcd
LcdReg = %00100000 'LCD Standard Commands, Horizontal addressing mode.
call PrintCtrlLcd
call CursorHome
Call TableTemp
Main:
LcdReg = %00001100 'LCD in normal mode. - ovisi o položaju jumpera
if Mode = 1 then LcdReg = %00001101 'LCD in inverse mode.
call PrintCtrlLcd
OWOut DQ, 1, [$CC, $BE] ' pročitaj temperaturu iz DS18B20
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
Predznak = 0
if TempHigh.7 = 1 then temperature = (~ temperature) + 1 : Predznak = 1
TempH = temperature >> 4
Templ = temperature.lowbyte & $0f
Temperature = templ * 625
OWOut DQ, 1, [$CC, $44] ' Start konverzije temperature ( 12 bit.- trajanje oko 700ms )
LcdReg = %10000000 + 12 ' cursor X
call PrintCtrlLcd
LcdReg = %01000011 ' cursor Y
call PrintCtrlLcd
if TempH > 99 then ' ako je temp. veca od 99'C, umjesto plusa napisi "1"
Char = 1 ' stotice
call PrintChar
else
Char = 10 ' + plus
if Predznak = 1 then Char = 11 ' - minus
call PrintChar
endif
Char = (temph dig 1) ' desetice
call PrintChar
Char = (temph dig 0) ' jedinice
call PrintChar
Char = 12 ' točka
call PrintChar
Char = (temperature dig 3) ' prva decimala
Call PrintChar
call MinusNaSkali ' ako je temperatura " minus " , nacrtaj minuse na skali
skala[0] = $ff
skala[1] = $ff
skala[2] = $ff
skala[3] = $ff
if temph > 32 then goto PrintSkala
temph = 32 - temph
for y = 1 to temph
skala[0] = skala[0] << 1
next y
for y = 9 to temph
skala[1] = skala[1] << 1
next y
for y = 17 to temph
skala[2] = skala[2] << 1
next y
for y = 25 to temph
skala[3] = skala[3] << 1
next y
PrintSkala:
for y = 0 to 3
call SetCursor
LcdReg = skala[y]
call PrintDataLcd
next y
nap 6 ' sleep 1,152 sec.
Goto main
SetCursor: LcdReg = %10000000 + 76 ' cursor X
call PrintCtrlLcd
LcdReg = %01000001 + y ' cursor Y
call PrintCtrlLcd
return
'-------------------------------------------------------------------------------
MinusNaSkali: minus = 0
if predznak = 1 then Minus = $04
LcdReg = %10000000 + 63 ' cursor X
call PrintCtrlLcd
LcdReg = %01000000 + 3 ' cursor Y minus ispred 10
call PrintCtrlLcd
LcdReg = Minus
call PrintDataLcd
LcdReg = Minus
call PrintDataLcd
if predznak = 1 then Minus = $01
LcdReg = %10000000 + 61 ' cursor X minus ispred 20
call PrintCtrlLcd
LcdReg = %01000000 + 2 ' cursor Y
call PrintCtrlLcd
LcdReg = Minus
call PrintDataLcd
LcdReg = Minus
call PrintDataLcd
Minus = $01
if predznak = 1 then Minus = $41
LcdReg = %10000000 + 61 ' cursor X minus ispred 30
call PrintCtrlLcd
LcdReg = %01000000 + 0 ' cursor Y
call PrintCtrlLcd
LcdReg = Minus
call PrintDataLcd
LcdReg = Minus
call PrintDataLcd
return
'-------------------------------------------------------------------------------
CursorHome: LcdReg = %10000000 ' cursor Home
call PrintCtrlLcd
LcdReg = %01000000 ' cursor Home
call PrintCtrlLcd
return
PrintChar: offset = Char * 5
for a = 1 to 5
read offset, LcdReg
call PrintDataLcd
offset = offset + 1
next a
LcdReg = 0
call PrintDataLcd
return
@ org 0x21C
TableTemp:
for y = 65 to 127
read y, LcdReg
call PrintDataLcd
next y
for y = 0 to 194 ' drugi dio slike
LOokup y, [$01,$A1,$11,$51,$A1,$01,$E1,$11,$11,$E1,$01,$81,$41,$41,$41,$81,$01,_
$01,$01,$01,$FF,$FF,$00,$00,$FF,$00,$21,$20,$3C,$23,$06,$39,$60,_
$80,$A3,$BD,$2B,$2D,$33,$80,$FF,$00,$00,$00,$00,$0F,$0F,$0F,$00,_
$00,$00,$03,$07,$0F,$0D,$0D,$0D,$05,$00,$0F,$0F,$0F,$00,$0F,$0F,_
$0F,$00,$0F,$0F,$0F,$00,$3F,$3F,$3F,$04,$0F,$0F,$07,$00,$0C,$0C,_
$00,$00,$00,$04,$84,$45,$45,$84,$04,$84,$45,$45,$84,$00,$FF,$00,_
$00,$00,$FF,$00,$84,$04,$00,$FF,$FF,$00,$00,$00,$E1,$F2,$12,$12,_
$12,$12,$12,$12,$12,$12,$12,$12,$12,$13,$13,$13,$10,$10,$08,$04,_
$02,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,_
$01,$01,$01,$01,$01,$01,$81,$81,$81,$01,$01,$01,$01,$01,$01,$01,_
$01,$01,$01,$FE,$00,$00,$00,$10,$14,$16,$15,$14,$10,$13,$14,$14,_
$13,$00,$FF,$00,$00,$00,$FF,$00,$10,$10,$00,$FF,$FF,$00,$00,$00,_
$FF,$FF] ,LcdReg
call PrintDataLcd
next y
LcdReg = 0
for y = 1 to 40
call PrintDataLcd
next y
for y = 0 to 205 ' treci dio slike
LOokup y, [$03,$02,$03,$00,$00,$3E,_
$41,$41,$41,$23,$00,$00,$00,$FF,$00,$00,$00,$40,$40,$40,$41,$5F,_
$40,$4E,$51,$51,$4E,$00,$FF,$00,$00,$00,$FF,$00,$42,$40,$00,$FF,_
$FF,$00,$40,$C0,$47,$47,$46,$86,$06,$06,$06,$06,$06,$86,$C6,$06,_
$86,$46,$46,$86,$06,$46,$C6,$46,$46,$86,$06,$86,$46,$46,$86,$06,_
$86,$46,$46,$86,$06,$06,$06,$86,$46,$86,$06,$06,$06,$06,$06,$46,_
$C6,$46,$46,$86,$06,$46,$06,$06,$06,$06,$02,$01,$80,$C0,$00,$80,_
$40,$40,$80,$00,$40,$C0,$40,$40,$C0,$00,$FF,$00,$00,$00,$FF,$00,_
$08,$00,$00,$FF,$FF,$80,$90,$9F,$90,$90,$90,$8F,$80,$92,$95,$89,_
$80,$80,$9F,$80,$8D,$92,$92,$8D,$80,$90,$9F,$92,$92,$8D,$80,$98,_
$94,$92,$99,$80,$8F,$90,$90,$8F,$80,$80,$80,$8E,$91,$92,$8D,$93,_
$80,$80,$80,$90,$9F,$92,$82,$81,$80,$9F,$80,$8E,$91,$91,$8A,$80,_
$80,$9F,$80,$98,$94,$92,$99,$80,$90,$9F,$92,$82,$80,$9E,$BF,$BF,_
$BF,$BF,$BF,$9E,$81,$81,$80,$FF] ,LcdReg
call PrintDataLcd
next y
return
PrintCtrlLcd: D_C = 0
PrintDataLcd: for x = 1 to 8 ' ispis na Lcd
SDIN = LcdReg.7
LcdReg = LcdReg << 1
SCK = 1
SCK = 0
next x
D_C = 1
return
end