Migration problems

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Texy
Posts: 54
Joined: 23 Mar 2009 22:00

Migration problems

#1 Post by Texy » 15 Apr 2009 18:49

I,m having problems migrating to basic pro with the following code

Code: Select all


program Usart_Test
    dim x as byte
    dim result as byte
    dim y as word
    dim output1 as string[3]
'===============================================================================
    sub procedure Soft_Uart_Write_Text(dim byref txt as string[50])
        dim i as byte

        for i = 0 to Strlen(txt) - 1
            Soft_Uart_Write(txt[i])
'            delay_ms(10)
        next i
    end sub
'===============================================================================

main:
   OSCCON = $7E    ' set for intrc @ 8mhz
   ANSEL = 0
   'ADCON0.0 = 0
'   TRISA = 0                     'Configure pins of PORTA as output
   'TRISB = %00000100               'Configure first pin of PORTB as input and the rest as output
   'INTCON = %10010000               'Enable Interrupts
PORTB =0
TRISB=0
CMCON=7

  delay_ms(100)
'  PORTB=0
   soft_Uart_Init(PORTB,2,5,9600,1)
Delay_ms(100)
   PORTA = 0

      soft_Uart_Write(13)
      soft_Uart_Write(10)
      soft_Uart_Write_Text("Hello World!")
'      Delay_ms(700)

delay_ms(100)

Soft_I2C_Config(PORTA,1,4)

Soft_I2C_start        ' issue I2C start signal
Soft_I2C_write($A0)   ' send Config byte via I2C
Soft_I2C_write($00)   ' send Hi byte (address of EEPROM location)
Soft_I2C_write($00)   ' send Lo byte (address of EEPROM location)
Soft_I2C_write($AA)   ' send data to EEPROM
Soft_I2C_stop
delay_ms(10)


Soft_I2C_start ' issue I2C start signal
Soft_I2C_write($A0) ' send Config byte via I2C
Soft_I2C_write($00) ' send Hi byte (address of EEPROM location)
Soft_I2C_write($01) ' send Lo byte (address of EEPROM location)
Soft_I2C_write($55) ' send data to EEPROM
Soft_I2C_stop
delay_ms(10)


Soft_I2C_start ' issue I2C start signal
Soft_I2C_write($A0) ' send Config byte via I2C
Soft_I2C_write($00) ' send Hi byte (address of EEPROM location)
Soft_I2C_write($00) ' send Lo byte (address of EEPROM location)
Soft_I2C_Start ' issue I2C signal repeated start
Soft_I2C_write($A1) ' send byte (request data from EEPROM)
result = Soft_I2C_read(0) ' Read the data
Soft_I2C_stop
delay_ms(10)
ByteToStr(result, output1)
soft_Uart_Write_Text(output1)

Soft_I2C_start ' issue I2C start signal
Soft_I2C_write($A0) ' send Config byte via I2C
Soft_I2C_write($00) ' send Hi byte (address of EEPROM location)
Soft_I2C_write($01) ' send Lo byte (address of EEPROM location)
Soft_I2C_Start ' issue I2C signal repeated start
Soft_I2C_write($A1) ' send byte (request data from EEPROM)
result = Soft_I2C_read(0) ' Read the data
Soft_I2C_stop
delay_ms(10)
ByteToStr(result, output1)
soft_Uart_Write_Text(output1)


end.
I get these errors :


34 348 Return value of the function "Soft_Uart_Write_Text" is not defined Usart_Test.mbas
38 304 Syntax error: Expected "end" but "main" found Usart_Test.mbas
38 304 Syntax error: Expected "." but ":" found Usart_Test.mbas
0 102 Finished (with errors): 15 Apr 2009, 18:37:52 usart_test.mbppi

Any idea's what is wrong?
Texy

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#2 Post by Bytex » 15 Apr 2009 20:59

Hello Texy,
This is your revised code. Now it sounds good for compilation.
There was a lot of problems.... :wink:

Code: Select all

program Usart_Test

dim x as byte
dim mresult as byte
dim y as word
dim output1 as string[3]
dim MyText as string[50]

    '// does not exist any more
    'Soft_I2C_Config(PORTA,1,4)

' Software I2C connections
dim Soft_I2C_Scl as sbit at RA4_bit
    Soft_I2C_Sda as sbit at RA1_bit
    Soft_I2C_Scl_Direction as sbit at TRISA4_bit
    Soft_I2C_Sda_Direction as sbit at TRISA1_bit
' End Software I2C connections

'===============================================================================

sub procedure Soft_Uart_Write_Text(dim byref mtxt as string[50])

    dim i as byte

    while (mtxt[i] <> 0)
        Soft_Uart_Write(mtxt[i])
        inc(i)
    wend

end sub
'===============================================================================

main:

    OSCCON = $7E    ' set for intrc @ 8mhz
    ANSEL = 0
    'ADCON0.0 = 0
    'TRISA = 0                     'Configure pins of PORTA as output
    'TRISB = %00000100               'Configure first pin of PORTB as input and the rest as output
    'INTCON = %10010000               'Enable Interrupts
    PORTB =0
    TRISB=0
    CMCON=7

    delay_ms(100)
    'PORTB=0
    soft_Uart_Init(PORTB,2,5,9600,1)
    Delay_ms(100)
    PORTA = 0

    soft_Uart_Write(13)
    soft_Uart_Write(10)
    MyText = "Hello World!"
    Soft_Uart_Write_Text(MyText)
    ' Delay_ms(700)

    delay_ms(100)

    '// does not exist any more
    'Soft_I2C_Config(PORTA,1,4)

    while true

        Soft_I2C_start        ' issue I2C start signal
        Soft_I2C_write($A0)   ' send Config byte via I2C
        Soft_I2C_write($00)   ' send Hi byte (address of EEPROM location)
        Soft_I2C_write($00)   ' send Lo byte (address of EEPROM location)
        Soft_I2C_write($AA)   ' send data to EEPROM
        Soft_I2C_stop
        delay_ms(10)

        Soft_I2C_start ' issue I2C start signal
        Soft_I2C_write($A0) ' send Config byte via I2C
        Soft_I2C_write($00) ' send Hi byte (address of EEPROM location)
        Soft_I2C_write($01) ' send Lo byte (address of EEPROM location)
        Soft_I2C_write($55) ' send data to EEPROM
        Soft_I2C_stop
        delay_ms(10)

        Soft_I2C_start ' issue I2C start signal
        Soft_I2C_write($A0) ' send Config byte via I2C
        Soft_I2C_write($00) ' send Hi byte (address of EEPROM location)
        Soft_I2C_write($00) ' send Lo byte (address of EEPROM location)
        Soft_I2C_Start ' issue I2C signal repeated start
        Soft_I2C_write($A1) ' send byte (request data from EEPROM)
        mresult = Soft_I2C_read(0) ' Read the data
        Soft_I2C_stop
        delay_ms(10)
        ByteToStr(mresult, output1)
        Soft_Uart_Write_Text(output1)

        Soft_I2C_start ' issue I2C start signal
        Soft_I2C_write($A0) ' send Config byte via I2C
        Soft_I2C_write($00) ' send Hi byte (address of EEPROM location)
        Soft_I2C_write($01) ' send Lo byte (address of EEPROM location)
        Soft_I2C_Start ' issue I2C signal repeated start
        Soft_I2C_write($A1) ' send byte (request data from EEPROM)
        mresult = Soft_I2C_read(0) ' Read the data
        Soft_I2C_stop
        delay_ms(10)
        ByteToStr(mresult, output1)
        Soft_Uart_Write_Text(output1)

    wend

end.

Regards.

Best regards,
Max

http://www.b-vu.com

Texy
Posts: 54
Joined: 23 Mar 2009 22:00

#3 Post by Texy » 16 Apr 2009 19:14

Thanks very much Max - almost there. However, the coomunication is not quite right, see this terminal output :


Hello World! 85 85

llo World!ïÿÿþ÷ÿþÿýÿÿÿýÿ*9+ïÿÿþ÷ÿþÿýÿÿÿýÿ*9+

The first line is from my basic program, the second from the basic pro version above. Not sure if the bytetostr routine is working, or what is wrong?

Texy

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#4 Post by Bytex » 16 Apr 2009 19:48

Hello Texy,
I have some questions:

What is your PIC ?

Why do you use PORTA for soft_I2C ?

Try to change to another port such B or C or you have to disable all analog function to put PORTA all digital.


Regards.

Best regards,
Max

http://www.b-vu.com

Texy
Posts: 54
Joined: 23 Mar 2009 22:00

#5 Post by Texy » 16 Apr 2009 20:20

hi Max
Pic is 16f88 - no port c
I am using existing design so those are currently free unused pins.
Ansel=0 makes ports digital.
The same hardware was used in the above example, I just uploaded the
Diffent hex files to give the different results.
Cheers
Texy

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#6 Post by Bytex » 16 Apr 2009 21:11

Ok
I'm sorry for my modifications. I've put a while..wend loop that in your original code doesn't exist.

Your original code does process only a one shot. Is it right ?

Best regards,
Max

http://www.b-vu.com

Texy
Posts: 54
Joined: 23 Mar 2009 22:00

#7 Post by Texy » 16 Apr 2009 21:44

Yes I took the loop out. This is just a test program to evaluate a different problem I have Reading from the EEPROM.
Thanks for you help so far
Texy

Post Reply

Return to “mikroBasic PRO for PIC General”