UART1 library bug???

General discussion on mikroBasic PRO for 8051.
Post Reply
Author
Message
SH007
Posts: 56
Joined: 29 Sep 2007 08:44

UART1 library bug???

#1 Post by SH007 » 09 Jun 2010 20:07

Hi,
Anyone faced issue in UART1 library...it looks to be not generating correct baud. Tested with Proteus. Bascom working fine.
Thanks
SH007

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: UART1 library bug???

#2 Post by tihomir.losic » 10 Jun 2010 15:28

Hello,

I have tested your program on real hardware. Specifically, I used Easy8051B development
board, and the program has worked without problems.
This leads to the conclusion that the error is in Proteus, your simulator.

Regards,

Losic Tihomir
mikroElektronika [Support team]

SH007
Posts: 56
Joined: 29 Sep 2007 08:44

Re: UART1 library bug???

#3 Post by SH007 » 10 Jun 2010 16:09

Dear I am 100% sure that the problem is in MB Pro. It is not generating correct baud rate. May be in real world it is working with error but you please recheck the asm listing. and also try different combinations of Frequency and baud.

MB Pro listing:
;Uart.mbas,29 :: UART1_Init(4800) ' Initialize UART module at 4800 bps
0x008D 0x758DFA MOV TH1, #250
0x0090 0x758BFA MOV TL1, #250



;Uart.mbas,29 :: UART1_Init(9600) ' Initialize UART module at 4800 bps
0x008D 0x758DFD MOV TH1, #253
0x0090 0x758BFD MOV TL1, #253


By some 8051 Calulator software:

For 4800:
;Replace x with timer no.
;Configure and Enable timer.
;Timer Clk=11.0592/12*1 = 0.9216 MHz
orl PCON,#0x80 ;Set SMOD
mov scon,#0x50 ;8-bit,rx enable
mov TLx,#0x00 ;Lower Byte
mov THx,#0xF4 ;Upper Byte
setb TRx ;Run timer


For 9600:
;Replace x with timer no.
;Configure and Enable timer.
;Timer Clk=11.0592/12*1 = 0.9216 MHz
orl PCON,#0x80 ;Set SMOD
mov scon,#0x50 ;8-bit,rx enable
mov TLx,#0x00 ;Lower Byte
mov THx,#0xFA ;Upper Byte
setb TRx ;Run timer


Thanks
SH007

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: UART1 library bug???

#4 Post by tihomir.losic » 11 Jun 2010 14:38

Hello,

please, create Support Ticket on our Support Desk:
http://www.mikroe.com/esupport
and send me your project in order to inspect your issue.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

SH007
Posts: 56
Joined: 29 Sep 2007 08:44

Re: UART1 library bug???

#5 Post by SH007 » 12 Jun 2010 08:38

Dear, As I am demo user I can not login your suggested page. Here is the simple loop back code. Attached picture shows the looop back results with MikroBasic Pro 8051 when type abcd.....xyz. and with the simple ASM example I received same correct as I typed.

program UART

dim uart_rd as byte
main:
UART1_Init(9600) ' Initialize UART module at 4800 bps
delay_ms(100)
while TRUE ' Endless loop
if (UART1_Data_Ready() <> 0) then ' If data is received,
uart_rd = UART1_Read() ' read the received data,
UART1_Write(uart_rd)
end if
wend
end.


; LST file generated by mikroListExporter - v.2.0
; Date/Time: 6/12/2010 12:21:11 PM
;----------------------------------------------

;Address Opcode ASM
0x0000 0x020075 LJMP 117
0x0003 0x020000 LJMP 0
0x0006 0x00 NOP
0x0007 0x00 NOP
0x0008 0x00 NOP
0x0009 0x00 NOP
0x000A 0x00 NOP
0x000B 0x020000 LJMP 0
0x000E 0x00 NOP
0x000F 0x00 NOP
0x0010 0x00 NOP
0x0011 0x00 NOP
0x0012 0x00 NOP
0x0013 0x020000 LJMP 0
0x0016 0x00 NOP
0x0017 0x00 NOP
0x0018 0x00 NOP
0x0019 0x00 NOP
0x001A 0x00 NOP
0x001B 0x020000 LJMP 0
0x001E 0x00 NOP
0x001F 0x00 NOP
0x0020 0x00 NOP
0x0021 0x00 NOP
0x0022 0x00 NOP
0x0023 0x020000 LJMP 0
0x0026 0x00 NOP
0x0027 0x00 NOP
0x0028 0x00 NOP
0x0029 0x00 NOP
0x002A 0x00 NOP
0x002B 0x020000 LJMP 0
_UART1_Write:
;__Lib_UART_Timer1.mpas,45 ::
;__Lib_UART_Timer1.mpas,46 ::
0x002E 0xC299 CLR SCON.B1
;__Lib_UART_Timer1.mpas,47 ::
0x0030 0x851299 MOV SBUF, FARG_UART1_Write_data_+0
;__Lib_UART_Timer1.mpas,48 ::
L__UART1_Write3:
0x0033 0x209903 JB SCON.B1, L__UART1_Write4
0x0036 0x00 NOP
0x0037 0x80FA SJMP L__UART1_Write3
L__UART1_Write4:
;__Lib_UART_Timer1.mpas,49 ::
0x0039 0xC299 CLR SCON.B1
;__Lib_UART_Timer1.mpas,50 ::
0x003B 0x22 RET
; end of _UART1_Write
_UART1_Init:
;__Lib_UART_Timer1.mpas,32 ::
;__Lib_UART_Timer1.mpas,33 ::
0x003C 0x750C2E MOV _UART_Wr_Ptr, #_UART1_Write+0
0x003F 0x750D00 MOV _UART_Wr_Ptr+1, hi(#_UART1_Write+0)
0x0042 0x750E12 MOV _UART_Wr_Ptr+2, #FARG_UART1_Write_data_+0
;__Lib_UART_Timer1.mpas,34 ::
0x0045 0x750F64 MOV _UART_Rd_Ptr, #_UART1_Read+0
0x0048 0x751000 MOV _UART_Rd_Ptr+1, hi(#_UART1_Read+0)
0x004B 0x751100 MOV _UART_Rd_Ptr+2, 0
;__Lib_UART_Timer1.mpas,35 ::
0x004E 0x75086C MOV _UART_Rdy_Ptr, #_UART1_Data_Ready+0
0x0051 0x750900 MOV _UART_Rdy_Ptr+1, hi(#_UART1_Data_Ready+0)
0x0054 0x750A00 MOV _UART_Rdy_Ptr+2, 0
;__Lib_UART_Timer1.mpas,38 ::
0x0057 0x759850 MOV SCON, #80
;__Lib_UART_Timer1.mpas,39 ::
0x005A 0x758780 MOV PCON, #128
;__Lib_UART_Timer1.mpas,40 ::
0x005D 0x758840 MOV TCON, #64
;__Lib_UART_Timer1.mpas,41 ::
0x0060 0x758920 MOV TMOD, #32
;__Lib_UART_Timer1.mpas,42 ::
0x0063 0x22 RET
; end of _UART1_Init
_UART1_Read:
;__Lib_UART_Timer1.mpas,58 ::
;__Lib_UART_Timer1.mpas,59 ::
0x0064 0xC298 CLR SCON.B0
;__Lib_UART_Timer1.mpas,60 ::
0x0066 0x859912 MOV UART1_Read_local_result, SBUF+0
;__Lib_UART_Timer1.mpas,61 ::
0x0069 0xA812 MOV R0, UART1_Read_local_result
0x006B 0x22 RET
; end of _UART1_Read
_UART1_Data_Ready:
;__Lib_UART_Timer1.mpas,53 ::
;__Lib_UART_Timer1.mpas,54 ::
0x006C 0xA298 MOV C, SCON.B0
0x006E 0xE4 CLR A
0x006F 0x33 RLC A
0x0070 0xF512 MOV UART1_Data_Ready_local_result, A
;__Lib_UART_Timer1.mpas,55 ::
0x0072 0xA812 MOV R0, UART1_Data_Ready_local_result
0x0074 0x22 RET
; end of _UART1_Data_Ready
_main:
0x0075 0x758180 MOV SP, #128
;Uart.mbas,28 :: main:
;Uart.mbas,29 :: UART1_Init(9600) ' Initialize UART module at 4800 bps
0x0078 0x758DFD MOV TH1, #253
0x007B 0x758BFD MOV TL1, #253
0x007E 0x113C ACALL _UART1_Init
;Uart.mbas,30 :: delay_ms(100)
0x0080 0x7EB4 MOV R6, 180
0x0082 0x7F4B MOV R7, 75
0x0084 0xDFFE DJNZ R7, PC-2
0x0086 0xDEFC DJNZ R6, PC-4
;Uart.mbas,31 :: while TRUE ' Endless loop
L__main2:
;Uart.mbas,32 :: if (UART1_Data_Ready() <> 0) then ' If data is received,
0x0088 0x116C ACALL _UART1_Data_Ready
0x008A 0xE8 MOV A, R0
0x008B 0x600A JZ L__main7
;Uart.mbas,33 :: uart_rd = UART1_Read() ' read the received data,
0x008D 0x1164 ACALL _UART1_Read
0x008F 0x85000B MOV _uart_rd, 0
;Uart.mbas,34 :: UART1_Write(uart_rd)
0x0092 0x850012 MOV FARG_UART1_Write_data_, 0
0x0095 0x112E ACALL _UART1_Write
L__main7:
;Uart.mbas,35 :: end if
0x0097 0x80EF SJMP L__main2
;Uart.mbas,36 :: wend
0x0099 0x80FE SJMP #254
; end of _main


###########################################################
Simple asm code that worked fine
#######################
$INCLUDE (reg_c51.INC)

org 000h
ljmp begin

org 23h
ljmp serial_IT

;/**
; * FUNCTION_PURPOSE: This file set up uart in mode 1 (8 bits uart) with
; * timer 1 in mode 2 (8 bits auto reload timer).
; * FUNCTION_INPUTS: void
; * FUNCTION_OUTPUTS: void
; */
org 0100h

begin:
MOV SCON, #50h; /* uart in mode 1 (8 bit), REN=1 */
ORL TMOD, #20h; /* Timer 1 in mode 2 */
MOV TH1, #0FDh; /* 9600 Bds at 11.059MHz */
MOV TL1, #0FDh; /* 9600 Bds at 11.059MHz */
SETB ES; /* Enable serial interrupt */
SETB EA; /* Enable global interrupt */
SETB TR1; /* Timer 1 run */

JMP $; /* endless */

;/**
; * FUNCTION_PURPOSE: serial interrupt, echo received data.
; * FUNCTION_INPUTS: P3.0(RXD) serial input
; * FUNCTION_OUTPUTS: P3.1(TXD) serial output
; */
serial_IT:
JNB RI,EMIT_IT ; test if it is a reception
CLR RI ; clear reception flag for next reception
MOV A,SBUF ; read data from uart
MOV SBUF,A ; write same data to uart
LJMP END_IT
EMIT_IT:
CLR TI ; clear transmition flag for next transmition

END_IT:
RETI

end
Attachments
That received back with MikroBasic Pro 8051 with abcd...xyz
That received back with MikroBasic Pro 8051 with abcd...xyz
virtualterminal.JPG (4.43 KiB) Viewed 5372 times

SH007
Posts: 56
Joined: 29 Sep 2007 08:44

Re: UART1 library bug???

#6 Post by SH007 » 12 Jun 2010 10:17

Sorry to say, I should be remain with BASCOM.
Thanks
SH007

Post Reply

Return to “mikroBasic PRO for 8051 General”