After I set up the LCD temperature display, I want to show temperature on the digits (7 segments) in this method (00,0C). I am using the MCU P16F628A, temperature sensor DS18B20 and 4 digit (7 segment) with common cathode. I read different documents and I noticed that we need to use interrupts so will take it easy.
Now can anyone help me getting the program from MikroBasic to MikroC. I started to learn MikroC language and it is easier to understand.
Code: Select all
SW:MikroBasic
program display
dim zz, j,j1,j2, v as byte
dim i,n,temp as word
dim por as byte[4]
dim cc as boolean
sub function Mask(dim num as byte) as byte ' this function returns masks
select case num ' for common cathode 7-seg. display
case 0 result = $3F
case 1 result = $06
case 2 result = $5B
case 3 result = $4F
case 4 result = $66
case 5 result = $6D
case 6 result = $7D
case 7 result = $07
case 8 result = $7F
case 9 result = $6F
end select 'case end
end sub
sub procedure interrupt
INTCON.TMR0IF = 0 ' Clear TMR0IF
PORTD = por[v] ' Send the appropriate mask to PORTB
PORTA = zz ' Turn on appropriate 7seg. display
Inc(v)
zz = zz << 1 ' Prepare for next digit
if zz > 8 then
zz = 1
end if
if v > 3 then
v = 0
end if
TMR0 = 0' Reset timer
end sub
main:
OPTION_REG = 0 '$80
adcon1 = 255
j = 0
v = 0
zz = 1
TMR0 = 0
INTCON = $A0 ' Disable PEIE,INTE,RBIE,T0IE
TRISA = 0
TRISD = 0
PORTD = 0
PORTA = 0
while true
INTCON.GIE = 0
ow_reset(PORTA, 5) ' onewire reset signal
ow_write(PORTA, 5, $CC) ' issue command to DS1820
ow_write(PORTA, 5, $44) ' issue command to DS1820
INTCON.GIE = 1
delay_ms(500) 'wait for conversion complete
INTCON.GIE = 0
cc = ow_reset(PORTA, 5)
ow_write(PORTA, 5, $CC) ' issue command to DS1820
ow_write(PORTA, 5, $BE) ' issue command to DS1820
j1 = ow_read(PORTA, 5) ' get result
j2 = ow_read(PORTA, 5) ' get result (assuming the temperature is positive)
INTCON.GIE = 1
if j2 = $FF then
'tmp_sign = "-" ' temperature sign
j1= j1 or $FF ' complement of two
j1= j1 + $01
'else
'tmp_sign = "+"
end if
j2 = (j1 and $01) * 5 ' Get decimal value
j1 = j1 >> 1 ' Form the 2byte variable
i= (j1*10) + j2
delay_ms(500)
j = i div 1000 ' prepare digits for diplays
por[3] = Mask(j)
j = i div 100 mod 10
por[2] = Mask(j)
j = i div 10 mod 10
por[1] = Mask(j)
j = i mod 10
por[0] = Mask(j)
wend
end.