Tuesday, February 24, 2009

First test code for the PIC16F877A

We visited the robotics help webpage:

ROBOT ELECTRONICS - 1st rule of Robotics: Have fun!

In this webpage we could find a variety of examples to control our SRF08. The owners of this code samples allows us to use them for educational purposes, but not commercial ones.

We found the following program, which would be the first in our set of tests with the PIC16F877A.

'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [Vladimir Kornienko] *
'* Notice : Copyright (c) 2006 [ARMORED DOLPHIN] *
'* : All Rights Reserved *
'* Date : 12/1/2006 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************

'PIC16f872

'---------------- Definitions---------------------------------------------

define OSC 20

'------------- Define LCD registers and bits------------------------------

DEFINE I2C_HOLD 1
define I2C_SLOW 1

Define LCD_DREG PORTB 'Set LCD data port
Define LCD_DBIT 0 'Set starting data bit
Define LCD_RSREG PORTB 'Set LCD register select port
Define LCD_RSBIT 4 'Set LCD register select bit
Define LCD_EREG PORTB 'Set LCD enable port
Define LCD_EBIT 5 'Set LCD enable bit
define DEBUG_REG PORTC 'Set DEBUD port
DEFINE DEBUG_BIT 1 'Set DEBUG pin
DEFINE DEBUG_BAUD 2400 'Set DEBUG baud rate
DEFINE DEBUG_MODE 0 'Set DEBUG mode

DPIN var PORTc.4 ' I2C data pin
CPIN var PORTc.3 ' I2C clock pin

bearing var word ' word size bearing value 0 - 359
bearing1 var byte ' byte size bearing value 0 - 254

Main:

i2cread dpin,cpin,%11000000,2,[bearing.Highbyte,bearing.lowbyte]
lcdout $fe, 1,"BEARING ",DEC BEARING/10
i2cread dpin,cpin,%11000000,1,[bearing1]
lcdout $fe, $c0,"Bearing ", dec bearing1
DEBUG " Compass Bearing ", # bearing,13,10
pause 20

goto main

No comments:

Post a Comment