Jump to content

Fandu

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Fandu

  • Rank
    Newbrie
  1. OK, I modified the code to just use a global array and everything compiles fine. Unfortunately it doesn't work I modified the USART routine to set it up for a 20MHz processor and 9600 baud ( spbrg = 32). All I'm getting out of the serial port when I run the program is 0x01. Is there any obvious reason for that? Also, I am using the Bloater boot loader, which needs the code origin at 0x0004. I noticed that SourceBasic is ignoring the pragma directive... How to I control code locations in SourceBasic? Thanks ' I2C - Serial Test Controller ' Uses PIC16F877A @ 20Mhz #pragma BOOTLOADER 0004 Dim msg_input(20) As Char ' Initialize 20 global character input buffer Sub prompt() call usart_tx(126) ' Print "-" call usart_tx(62) ' Print ">" End Sub Sub print_str(j As Integer) Dim k As Integer ' k - string position counter k = 0 Do while k < j call usart_tx( msg_input(k) ) ' Print out each character k = k + 1 Loop End Sub sub main() call prompt() Dim msg_i2caddr As String (40) Dim msg_readmem As String (40) Dim i As Integer ' i = # of characters in buffer i = 0 msg_i2caddr = "Set I2C Device Address = " ' Random strings msg_readmem = "Read IC2 Memory" call usart_init() 'Initialize software rs232 Do while 1 msg_input(i) = call usart_rx() If ( msg_input(i) = 13 ) Then ' If carrage return call print_str( i) ' Print out the string i = 0 ' Reset string length call usart_tx(10) ' Line Feed call prompt() End If If ( i = 19 ) Then ' If we have 20 characters call print_str( i) ' Print out the string i = 0 ' Reset string length call usart_tx(10) ' Line Feed call prompt() End If i = i + 1 Loop end sub
  2. Hey, I'm trying to learn to use Basic on the PIC and seem to be having trouble with array indexing and/or passing arrays to functions. I'm trying to write a simple program that will accept up to 20 characters from a PC over RS232, then simply echo those back when Enter is pressed. I'm getting compiler several compiler errors with this code: Sub prompt() call usart_tx(126) ' Print "-" call usart_tx(62) ' Print ">" End Sub Sub print_str( msg(20) As Char, j As Integer) Dim k As Integer ' k - string position counter k = 0 Do while k < j call usart_tx( msg(k) ) ' Print out each character. *** ERROR HERE *** k = k + 1 Loop End Sub sub main() Dim msg_input(20) As Char ' Initialize 20 character input buffer Dim msg_i2caddr As String (40) Dim msg_readmem As String (40) Dim i As Integer ' i = # of characters in buffer i = 0 msg_i2caddr = "Set I2C Device Address = " ' Random strings msg_readmem = "Read IC2 Memory" call usart_init() 'Initialize usart Do while 1 msg_input(i) = call usart_rx() If ( msg_input(i) = 13 ) Then ' If carrage return call print_str( msg_input, i) ' Print out the string *** ERROR HERE *** i = 0 ' Reset string length call usart_tx(10) ' Line Feed call prompt() End If i = i + 1 Loop end sub I'm using Punerjot Mangat's USART library. Target device is 16F877A @ 20Mhz
×
×
  • Create New...