hey
i am program pic16f688 to receive signal from the gyro (MG1101). i am using LAB-x4 development board. iam also using pic basic pro compiler. i sucessfully compile my program but not seeing anything thing appear on the LCD. for example i wanted for "gyro ready" or "hold still" to appear. could anyone help me out how to use the SEROUT command to have my pic running.below is my code.
************************************************** **************
'* Name : UNTITLED.BAS *
'* Author : [benedict tarr] *
'* Notice : Copyright (c) 2006 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 3/22/2006 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
' Define LCD registers and bits
include "modedefs.bas"
Define LCD_DREG PORTA
Define LCD_DBIT 4
Define LCD_RSREG PORTA
Define LCD_RSBIT 0
Define LCD_EREG PORTB
Define LCD_EBIT 1
LCD var PORTA.1
SCL VAR PORTC.1
SDA VAR PORTC.0
' EEPROM control = $A0
' Gyro control = $AE
address VAR Byte
x VAR BYTE
calibration VAR BYTE[16]
ar VAR WORD
br VAR WORD
ar_ave vAR WORD
br_ave VAR WORD
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTB.2 ' LCD R/W line low (W)
Pause 500 ' Wait for LCD and gyro to start up
SEROUT LCD, T2400, [$fe, 1] ' Clear screen
serout LCD, T2400, ["Begin Initialization"] ' Display message
'Read 15 calibration bytes and control register from EEPROM
address = 0
I2CREAD SDA, SCL, $A0, address, [STR calibration\16], i2cerr
' Set INIT and Power Mode 001 in control register value
calibration[$0F] = %01000001
' Write 15 calibration bytes and control register to gyro
I2CWRITE SDA, SCL, $AE, address, [STR calibration\16], i2cerr
PAUSE 10 ' needed??
serout LCD, T2400,["Waiting"] ' Message to user
' Begin polling GRNR bit
waitGRNR:
address = $08
I2CREAD SDA, SCL, $AE, address, [x], i2cerr
If x.1 = 1 Then waitGRNR ' If GRNR, continue polling
' GRNR is clear, display message and pause to let stabilize
serout LCD, T2400,["Gyro Ready", $FE, $C0, "Hold Still..."]
PAUSE 3000
' Take an average reading (64 samples) while gyro is motionless
ar_ave = 0
br_ave = 0
address = 0
For x = 0 to 63
pause 1
I2CREAD SDA, SCL, $AE, address, [ar.byte1, ar.byte0, br.byte1, br.byte0], i2cerr
ar_ave = ar_ave + (ar >> 6)
br_ave = br_ave + (br >> 6)
Next x
ar_ave = (ar_ave >> 6)
br_ave = (br_ave >> 6)
LCDOUT $FE, 1 ' Clear the display
loop:
' Get word values from gyro
I2CREAD SDA, SCL, $AE, address, [ar.byte1, ar.byte0, br.byte1, br.byte0], i2cerr
' Scale the values for readability (divide by 64), subtract from average,
' and display signed values as yaw and pitch
serout LCD, T2400,["Yaw: "], SDEC (ar_ave - (ar >> 6)),[" "],_
serout LCD, T2400,[$FE, $C0, "Pitch: "], SDEC (br_ave - (br >> 6)),[ " "]
Pause 100 ' Do it ten times a second
goto loop
i2cerr:
serout LCD, T2400,[$FE, 1, "I2C Error"]
STOP
Bookmarks