We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]
posted on 2013/02/06 03:08:35 AM CET
Hi
The code below dose work but dose not calculate the distance propply
can some kind person tell me what i am doing wrong
program MyPortB
#DEFINE OSC 20
' pic16f877
dim LCD_RS as sbit at RD2_bit
LCD_EN as sbit at RD3_bit
LCD_D4 as sbit at RD4_bit
LCD_D5 as sbit at RD5_bit
LCD_D6 as sbit at RD6_bit
LCD_D7 as sbit at RD7_bit
dim LCD_RS_Direction as sbit at TRISD2_bit
LCD_EN_Direction as sbit at TRISD3_bit
LCD_D4_Direction as sbit at TRISD4_bit
LCD_D5_Direction as sbit at TRISD5_bit
LCD_D6_Direction as sbit at TRISD6_bit
LCD_D7_Direction as sbit at TRISD7_bit
dim Triger as sbit at portb.2
dim ch as string[8]
dim number as word
main:
trisa=0
Trisb =0 ' designate portb as output (LCD is connected to portb)
trisc=0
portb=0
trisd=0
portd=0
trisb.4 =1
trisb.2=0
Lcd_Init() ' initialize (4-bit interface connection)
Lcd_Cmd(_LCD_CURSOR_OFF) ' send command to LCD (cursor off)
Lcd_Cmd(_LCD_CLEAR)
Lcd_Out(1,1,"Number")
number=00
while true '
Ow_Reset(PORTB, 4)
Triger =true '1 ' portb.2 =1
delay_us(50)
Triger =false ' 0 ' portb.2=0
number = Ow_Read(PORTB, 4)
number = number + (Ow_Read(PORTB, 4) << 8)
number = (number /2)/ 29.1
wordToStr(number, ch)
Lcd_Out(2,8,ch)
delay_us(500)
wend
' Main program
end.