radim na Easypic5, s PIC 18F14520, 8 MHz. Modificirao sam primjer Mikroelektronike kojim se provjerava OneWire procedura. Imam potrebu da pročitam temperaturu s DS18S20 preko pina RA.1. Isključio sam AD konverter, komparator, definirao LATA i TRISA kao ulaz. Dobivam samo nulu. Sa bilo kojeg drugog pina PORTA čitam temperaturur bez problema. Više namam ideja, a neznam gdje griješim. Može li netko mi pomoći?
Code: Select all
program OneWire
' Lcd module connections
dim LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D4 as sbit at RB0_bit
LCD_D5 as sbit at RB1_bit
LCD_D6 as sbit at RB2_bit
LCD_D7 as sbit at RB3_bit
LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
' End Lcd module connections
const TEMP_RESOLUTION as byte = 9
dim text as char[9]
temp as word
sub procedure Display_Temperature( dim temp2write as word )
const RES_SHIFT = TEMP_RESOLUTION - 8
dim temp_whole as byte
temp_fraction as word
text = "000.0000"
' Check if temperature is negative
if (temp2write and 0x8000) then
text[0] = "-"
temp2write = not temp2write + 1
end if
' Extract temp_whole
temp_whole = word(temp2write >> RES_SHIFT)
' Convert temp_whole to characters
if ( temp_whole div 100 ) then
text[0] = temp_whole div 100 + 48
else
text[0] = "0"
end if
text[1] = (temp_whole div 10)mod 10 + 48 ' Extract tens digit
text[2] = temp_whole mod 10 + 48 ' Extract ones digit
' Extract temp_fraction and convert it to unsigned int
temp_fraction = word(temp2write << (4-RES_SHIFT))
temp_fraction = temp_fraction and 0x000F
temp_fraction = temp_fraction * 625
' Convert temp_fraction to characters
text[4] = word(temp_fraction div 1000) + 48 ' Extract thousands digit
text[5] = word((temp_fraction div 100)mod 10 + 48) ' Extract hundreds digit
text[6] = word((temp_fraction div 10)mod 10 + 48) ' Extract tens digit
text[7] = word(temp_fraction mod 10) + 48 ' Extract ones digit
' Print temperature on Lcd
Lcd_Out(2, 5, text)
end sub
main:
ADCON0=0x00 ' AD Converter module is disabled
ADCON1=0x0E ' All pins are digital I/O
CMCON=0x07 ' Comparator module is disabled
LATA=1
TRISA=0XFF ' All pins RA are input
text = "000.0000"
Lcd_Init() ' Initialize Lcd
Lcd_Cmd(_LCD_CLEAR) ' Clear Lcd
Lcd_Cmd(_LCD_CURSOR_OFF) ' Turn cursor off
Lcd_Out(1, 1, " Temperature:")
Lcd_Chr(2,13,223) ' Print degree character, "C" for Centigrades
' Different Lcd displays have different char code for degree
Lcd_Chr(2,14,"C") ' If you see greek alpha letter try typing 178 instead of 223
'--- Main loop
while (TRUE)
'--- Perform temperature reading
Ow_Reset(PORTA, 1) ' Onewire reset signal
Ow_Write(PORTA, 1, 0xCC) ' Issue command SKIP_ROM
Ow_Write(PORTA, 1, 0x44) ' Issue command CONVERT_T
Delay_us(120)
Ow_Reset(PORTA, 1)
Ow_Write(PORTA, 1, 0xCC) ' Issue command SKIP_ROM
Ow_Write(PORTA, 1, 0xBE) ' Issue command READ_SCRATCHPAD
temp = Ow_Read(PORTA, 1)
temp = (Ow_Read(PORTA, 1) << 8) + temp
'--- Format and display result on Lcd
Display_Temperature(temp)
Delay_ms(520)
wend
end.