PDA

View Full Version : PIC 18F2220 from hell



RCTrepoman
- 18th November 2008, 03:42
Hello Folks,

I am a noob when it comes to pic programin. so i am hoping to enlist the help from some of the experts of this forum. I have been having a heck of a time trying to compile a program using PBP 2.50B and MCS+ 3.0.05. I am trying to receive a serial 8N1 formated string @ 38.4K baud and output it at 9.6K baud. When i attempt tocompile i get the following errors:


Error[108] c:pbp\pbppic18.lib 55 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 55 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 61 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 61 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 67 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 67 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 73 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 73 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 79 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 79 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 85 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 85 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 91 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 91 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 97 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 97 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 103 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 103 : Illeagal argument
Error[108] c:pbp\pbppic18.lib 109 : Illeagal character (=)
Error[124] c:pbp\pbppic18.lib 109 : Illeagal argument

I would appreciate any help and comments.

thank you

here is the code:


'Configuration Bits
@ INCLUDE "P18F2220.INC" ;processor specific variable definitions

@ LIST P=18F2220 ;directive to define processor and file format


@ __CONFIG _CONFIG1H, _IESO_OFF_1H & _FSCM_OFF_1H & _ECIO_OSC_1H
@ __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_27_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_32K_2H
@ __CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBAD_DIG_3H & _CCP2MX_C1_3H
@ __CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_OFF_4L

' Define Oscilator speed
DEFINE OSC = 20

RCSTA = $FAB
TXSTA = $FAC
SPBRG = $FAF

' Disable Analog Ports
ADCON1 = %00001111 ' Set all ports for digital operation

' Setup Imterups
INTCON = %01000000

data_ready_to_send var bit
UVSSIN var byte
RCTOUT var byte

'Use any spare port bits for flow control.

flow_control_input var PORTB.4
flow_control_output var PORTB.5

' Configure the flow-control pins as one input and one output.

TRISB.4 = 1
TRISB.5 = 0
TRISC.6 = 0 ' Setup pin RC6 to transmit
TRISC.7 = 1

' Assert the flow-control output to enable receiving data on the serial port.

flow_control_output = 0

data_ready_to_send = 0

loop:

' The main program loop.

gosub receive_serial_data
gosub transmit_serial_data

GOTO loop

receive_serial_data:

if (PIR1.5 = 1) then

' Tell the remote computer to stop sending data .

flow_control_output = 1

Poke SPBRG, 32

' A byte has arrived at the serial port. Read it.

SERIN2 PORTC.6,32774,[RCTOUT]

else

data_ready_to_send = 1

endif
return

transmit_serial_data:

if (data_ready_to_send = 1) then

' A byte is ready to send on the serial port.

if (flow_control_input = 0) then

' The flow control input is asserted.

Poke SPBRG, 129 ' Set baud rate to 9600

data_ready_to_send = 0

SEROUT2 PORTC.7\PORTC.4,84,[RCTOUT]

' Tell the remote computer it's OK to send more data.

flow_control_output = 0

endif
endif
return

mister_e
- 18th November 2008, 03:53
Hi and welcome here.

There's a few things you have to change and delete. Let's see


@ INCLUDE "P18F2220.INC" ;processor specific variable definitions
@ LIST P=18F2220 ;directive to define processor and file format

you don't need them, PBP do it for you, just delete those lines above


DEFINE OSC = 20
must be written like

DEFINE OSC 20
However, with this changed, you'll also need to change your OSC mode in your config fuses... and then you'll probably have a list of Error[118]... read the following thread (at least post 1 and 5)
http://www.picbasic.co.uk/forum/showthread.php?t=543


RCSTA = $FAB
TXSTA = $FAC
SPBRG = $FAF
kinda hard to fit a 12bit result in a 8bit register ;) Your program don't use the USART as it use a bit-banged solution (SERIN2/SEROUT2). If you want to use the USART, have a look in your manual for HSEROUT/HSERIN

HTH

RCTrepoman
- 18th November 2008, 04:19
Hello Steve,

Thank you for your reply. I was not sure if i need those first two lines of code. I will apply your recommendations when i get home.

Using HSERIN, will it read data @ 38.4K assuming I DEFINE the correct BAUD and SPBRG?

mister_e
- 18th November 2008, 04:24
Yes it will work. In fact you can change the baudrate on the fly if you need. If you do so, you'll need to change the SPBRG value.

Have a look at my PicMultiCalc, kinda handy stuff to calculate the SPBRG register

Download it here (http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2957&d=1225550328)

RCTrepoman
- 18th November 2008, 20:00
Hello Steve,

Your advice was right on. Thank you for taking the time to respond. Wihile i am fairly new to this forum, I have learned a lot from you and others who contribute to this forum regularly. The PicMultiCalc tool was very useful i will make good use of it. Thanks again.:D