Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] LCD with PIC16F877A problem

Status
Not open for further replies.
Hey
Now I'm using MicroCode studio Compiler
This is my code
Code:
'*********************************************************************************************
' Sonar-ranger.bas
' Program to control the Devantech SRF04 ultrasonic module. Measure 
' the distance between the the unit and an object. Convert the raw 
' data to inches and centimeters and then send the results to an LCD
' display. PicBasic Pro Compiler by MicroEngineering Labs. The 
' conversion factors listed in the SRF04 manual are for the PULSIN 
' of a Basic Stamp II which measures in 2us increments. When running
' a PICmicro MCU at 4 MHz and using the PicBasic Pro compiler the
' PULSIN command measures in 10us increments and the PULSOUT command
' also generates pulses with 10us increments. The adjusted conversion
' factors for 10us increments are:
' inches = raw_data / 15
' centimeters = raw_data / 6

'in picbasic stamp "  convert to inch ---> 1 / 73.746 
'                     convert to cm ---> ' 1 / 29.034 
'10us in picbasic pro but in basic stamp 2us for pulse so :
'The adjusted conversion factors for 10us increments are:
' inches = raw_data / 15     ' 73.746 / 5   =~ 15
' centimeters = raw_data / 6  ' 29.034 / 5 =~6
'*********************************************************************************************

 'Set LCD Data port
DEFINE LCD_DREG PORTB
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTB
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTB
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50


trisa = %00000001	
TrisB=0		
Buzzer   var PORTA.1

'*********************************************************************************************
' variables adapted for PING)))(TM) Ultrasonic Range Finder (#28015) by Kenneth Wong (2006/06/07)
' trigger      var PORTB.2
' echo         var PORTB.3
sonar       VAR PORTb.2
'*********************************************************************************************

dist_raw     var word
dist_inch    var word
dist_cm      var word
conv_inch    con 15
conv_cm      con 6



Lcdout $fe,1           			' clear lcd screen

pause 1000						' give time to initialize lcd

Lcdout $fe,$80,"- Sonar Ranger -"		' display program title on the LCD

sound Buzzer,[100,10,50,5,70,10,50,2]			' Make startup sound
                                               
pause 1000						' wait for 1 second

Lcdout $fe,1

Lcdout $fe,$80,"inches:"   	' set up the LCD display

Lcdout $fe,$C0,"cent:"

main:

     gosub sr_sonar					' get sonar reading

     
     
    Lcdout $fe,$89,#dist_inch," Inch "		' display the distance in inches

    Lcdout $fe,$C7,#dist_cm," cm "		' display the distance in centimeters

Goto main



sr_sonar:

'*********************************************************************************************
' I/O assignments adapted for PING)))(TM) Ultrasonic Range Finder (#28015) by Kenneth Wong (2006/06/07)
        output  sonar               ' set sonar pin as output
        low     sonar               ' logic low for sonar pin
        pulsout sonar,1				' send a 10us trigger pulse to the SRF04
        
        input   sonar               ' set sonar pin as input
        pulsin  sonar,1,dist_raw	' start timing the pulse width on echo pin 
'*********************************************************************************************

         dist_inch = (dist_raw/conv_inch)		' Convert raw data into inches 
         dist_cm = (dist_raw/conv_cm)		' Convert raw data into centimeters
         pause 1					' wait for 10us before returning to main

return

end
 

It seem that this have something to do with the type of LCD used
I have the same project running on 20 Mhz and working fine with a different type of LCD !!
Even though I tried 3 different type till now
 

Thanks for you help
the problem was with my hardware, I changed the PIC with a new one and everything worked just fine.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top