Uart_Init Missing?

General discussion on mikroBasic PRO for 8051.
Post Reply
Author
Message
dracosilv
Posts: 9
Joined: 16 Jun 2006 05:41
Location: Kenosha, Wisconsin
Contact:

Uart_Init Missing?

#1 Post by dracosilv » 22 Aug 2009 08:01

I noticed in the latest version of mikroBasic PRO for 8051, the Uart_Init routines are missing. Instead Now there is these UARTx commands.

I try typing:

Code: Select all

UARTx_Init(1200)
and this is the result:

Code: Select all

8 303 Identifier "UARTx_Init" was not declared EEPROM.mbas
8 303 Identifier "UARTx_Init" was not declared EEPROM.mbas
8 304 Syntax error: Expected "end" but "UARTx_Init" found EEPROM.mbas
8 304 Syntax error: Expected "." but "(" found EEPROM.mbas
0 102 Finished (with errors): 22 Aug 2009, 01:57:16 EEPROM.mbp51
and it gives me that error even if I use all libraries.

I don't see how I can use the hardware UART on my AT89C2051, when a version or two ago, I could.[/code]

foravr
Posts: 130
Joined: 11 May 2009 19:34

#2 Post by foravr » 23 Aug 2009 02:53

Hi,
UARTx_Init(1200)

x stays for the number of your uart. The new software is able to support more then one uart (usart) if available on your chip.

write UART1_Init(1200)

foravr

dracosilv
Posts: 9
Joined: 16 Jun 2006 05:41
Location: Kenosha, Wisconsin
Contact:

#3 Post by dracosilv » 23 Aug 2009 07:34

Okay. I figured that would be the case (X being the UART number), but I seem to still be having issues.

Code: Select all

4 303 Identifier "UART1_Init" was not declared EEPROM.mbas
0 102 Finished (with errors): 23 Aug 2009, 01:31:21 EEPROM.mbp51

Code: Select all

program EEPROM

' Declarations section 
UART1_Init(1200)

main:
'   Main program

end.
That's the error and the simple (very simple) test-code. Where am I still going wrong?

foravr
Posts: 130
Joined: 11 May 2009 19:34

#4 Post by foravr » 23 Aug 2009 09:33

Hi,
program EEPROM

' Declarations section
UART1_Init(1200)

main:
' Main program

end.

That's the error and the simple (very simple) test-code. Where am I still going wrong?
uart1_init is no declaration. it is a function call. put it after "main:"

i have tried your chip with "easy8051 uart example " - it works!
may i advise you to try the examples supplied with 8051basic pro?
they are a great help.

foravr

LQd
Posts: 13
Joined: 10 Jan 2011 16:21

Re: Uart_Init Missing?

#5 Post by LQd » 10 Jan 2011 16:41

Hello,
it looks like I have similar problem, I don't like to ask stupid questions, but this time I must. Compiler gets me the same error. I tried everything but nothing helped. I found that I have no Uart library available in project for AT89C2051, I also tried create project for MCU used as example in manual PDF and there the library was. Where is the problem?

Code: Select all

error: 7	303	Identifier "UART1_Init" was not declared	pokusy.mbas
error: 10	304	Syntax error: Expected "end" but "read" found	pokusy.mbas
error: 10	304	Syntax error: Expected "." but ":" found	pokusy.mbas
error: 0	102	Finished (with errors): 10 I 2011, 16:38:15	pokusy.mbp51
and this is sample of my code, if needed

Code: Select all

program pokusy

dim receive as byte

main:

UART1_init(9600)
Delay_ms(100)

read:

if (Uart1_Data_Ready = 1) then
   receive = Uart1_Read()
   Uart1_Write(receive)
   P1 = receive
else
    goto read
end if

end.
I don't want to use software Uart, because it is blocking function, and also there is no need to do it, MCU has hardware serial port.

Thanks a lot for help

LQd
Posts: 13
Joined: 10 Jan 2011 16:21

Re: Uart_Init Missing?

#6 Post by LQd » 20 Feb 2011 19:36

OK, no one wants to help, so I must help myself.
I wrote simple (working) example how to use HARDWARE BASED SERIAL PORT, mode 1 (8 bit async, 1 stop bit, timed by timer 1, TxD/P3.1, RxD/P3.0) on AT89C2051 or AT98C4051, maybe others with some tweaks, use it for your projects if you want and feel free to ask, if something isn't clear.
Note that SerialISR() procedure serves serial port and other code works independently on it, but is interrupted when event on serial port occur so be aware of using time critical applications, especially if you are receiving or sending byte after byte without pause (SerialISR() must fit into two events). And Timer 1 is occupied by serial port so you can't use it.

Baudrate can be calculated using this:
Baudrate = ((2^SMOD)/32)*(Xtal frequency/(12*(256-TH1)))
+-5% tolerance is allowed

Code: Select all

program na_forum

' Declarations section
dim temp as byte
'-------------------------------------------------------
sub procedure SerialISR() org 0x0023
'if data was received or send, this procedure start
'if RI_bit = 1, data received:

    if RI_bit = 1  then
       RI_bit = 0     'we must clear received data indicator
       temp = SBUF    'now we can work with data here or outside of procedure
       P1 = temp      'for example
       SBUF = temp    'or we can send the data back for echo
    end if

'if TI_bit = 1 data was successfully send
    if TI_bit = 1  then
       TI_bit = 0     'we must clear send data indicator
    end if
    
end sub

main:
'   Main program

'Serial port initialization
TH1 = 243           'Timer 1 value, sets baudrate, 9600 here
TMOD = %00100000    'sets  the timer mode
SCON = %01010000    'sets serial chanel: 8bit async timed by timer 1
EA_bit = 1          'enable interrupt
ES_bit = 1          'interrupt from serial chanel
TR1_bit = 1         'start timer 1
PCON = %10000000    'set SMOD bit to 1 - baudrate setting
'end of serial port initialization

'other code here:
do_nothing:           'wait to eternity or death :-)
Delay_ms(1000)
goto do_nothing

end.

Post Reply

Return to “mikroBasic PRO for 8051 General”