Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Serial RS232 and Interrupt

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051
View previous topic :: View next topic  
Author Message
dl7sep

Bascom Member



Joined: 26 Feb 2006
Posts: 81

germany.gif
PostPosted: Fri Dec 12, 2008 3:58 pm    Post subject: Serial RS232 and Interrupt Reply with quote

Hi,

have anybody experience about Hardware Uart with Bascom and
Intterupt with SCON.0 and SCON.1.

I had searched in the Bascom Help, but it gives no examples about this.

I would like to connect two Prozessor's (AT89S8252) with the Harware
Uart Pins.

Some test's about this give no reasonable result.
Have anybody a little example about this?

In the AVR Forum it gives many many examples, why not with the
Bascom8051?

Many thanks

Sepp
Back to top
View user's profile
Gianni

Bascom Member



Joined: 09 Jul 2004
Posts: 61
Location: Italy

blank.gif
PostPosted: Sat Dec 13, 2008 7:24 am    Post subject: Reply with quote

In the samples folder there is "serialbuf.bas".
Regards
Back to top
View user's profile
dl7sep

Bascom Member



Joined: 26 Feb 2006
Posts: 81

germany.gif
PostPosted: Sat Dec 13, 2008 10:22 am    Post subject: Reply with quote

Thanks Gianni,

i already saw that but it takes the "INPUT" instruction.
That is the normally Bascom instruction.
The routine "SENDCHAR" and "RECCHAR" are not in used, and they are
for me a little bit difficult.
You must handle your register save by yourself.

In the header it gives no information of the bauderate and how many Bit's
start- and stopbit and so on.

Look at this example written by Roland Walter for the AVR Series:

Code:


'0011.BAS: Optimierter String-Empfang
$Regfile = "2313def.dat"
$Crystal = 3686400
$Baud    = 9600

Dim s As String*10 At &H60
Dim b(11) As Byte At &H60 Overlay
Dim n As Byte

On URXC OnRxD
Enable URXC
Enable Interrupts

Main:
  If n > 9 Then
    Print s
    n = 0
  End If
Goto Main

OnRxD:
  Incr n
  b(n) = UDR
Return

 


Give it a chance to get the same with Bascom8051 ?

Thanks

Regards

Sepp
Back to top
View user's profile
Gianni

Bascom Member



Joined: 09 Jul 2004
Posts: 61
Location: Italy

blank.gif
PostPosted: Sat Dec 13, 2008 8:25 pm    Post subject: Reply with quote

Quote:
i already saw that but it takes the "INPUT" instruction.
That is the normally Bascom instruction.

Of course, this is the simplest way to implement a serial interrupt routine.
The received characters are stored in the circular buffer and the "INPUT" gets the character from the buffer,these operation are totally transparent to you.
Quote:
The routine "SENDCHAR" and "RECCHAR" are not in used, and they are
for me a little bit difficult.
You must handle your register save by yourself.

Code:
'first we tell the compiler about our routines
$serialoutput = Sendchar
$serialinput = Recchar

This redirect the default serial input & output routines to Recchar & Sendchar
Quote:
In the header it gives no information of the bauderate and how many Bit's
start- and stopbit and so on.

These routines do not involves the baud rate and uart format; you have to configure yourself.
The default format is 8bit, no parity, 1 stop bit; the baud rate depends (if you use timer1) from :
$baud = baurateYOUwant , and $crystal = crystalYOUuse . You have to set them.
Quote:
Look at this example written by Roland Walter for the AVR Series:

Of course you can write your own interrupt routine in basic; but it is more efficient and fast use the assembler.
Are you sure that your application really needs a serial interrupt receive routine.
Regards
Back to top
View user's profile
dl7sep

Bascom Member



Joined: 26 Feb 2006
Posts: 81

germany.gif
PostPosted: Sun Dec 14, 2008 9:43 am    Post subject: Reply with quote

Hi Gianni,

thanks for reply.

Ok, which I would like to do:

Two microprozessor are connected with the uart Pins.
One microprozessor send data to the second. But it gives no timeschematic from the first prozessor it can send in different times.

So the second prozessor must react when data comes to the uart-register.

For me it is a better solution to make this with a serial interupt, a "Input"
wait for "Timeout" or for a char and the prozessor can do nothing else.


So i found i a old forum the "AN30" SMS7 Phone application that use what i want.

I want do test this next week.

Thanks

Regards

Sepp

I want do test this at next week.
Back to top
View user's profile
dl7sep

Bascom Member



Joined: 26 Feb 2006
Posts: 81

germany.gif
PostPosted: Sun Dec 21, 2008 7:46 pm    Post subject: Reply with quote

Now i have a running solution for the serial UART with Interrupt for
the Rx.
My question is about SCON
In the Datasheet i can read:

TI SCON.1 Transmit interrupt flag. Set by hardware at the end of the 8th bit time in Mode 0, or at the beginning of the
stop bit in the other modes, in any serial transmission. Must be cleared by software.

RI SCON.0 Receive interrupt flag. Set by hardware at the end of the 8th bit time in Mode 0, or halfway through the
stop bit time in the other modes, in any serial reception (except see SM2). Must be cleared by software.

But my Rx runs only, when i cleared SCON.1 Bit for Transmit by software.

Have any a idea about this?

Here is the running test code

TX:

Code:


' **********************************************************************
' **        Program name: SERIAL_SEND  - Version : 1.0  21.12.2008    **
' **        Compiler : BASCOM 8051, ( V2.0.14.0)                      **
' **        Prozessor: 89S8252                                        **
' **                                                                  **
' **                                                                  **
' **                                                                  **
' **                                                                  **
' **                                                                  **
' **                                                                  **
' **        Written by:  Sepp Bartl                                   **
' **********************************************************************

   $regfile = "89s8252.DAT"                                   'use the 89S8252.DAT file
   $baud = 19200                                              'Baud Rate
   $crystal = 22118400
'-------------------------------------------------------------------------------
'
  '$sim                                                       'only for Simulation
   $large                                                     'for large Programm
'-------------------------------------------------------------------------------
'                 Temporary Variables
      Dim A As Byte                                           'Temp for Wait_sec
      Dim Time As Byte                                        'Temp for Wait_sec Time
      Dim S_buf As Byte                                       'Temp for Uart
'-------------------------------------------------------------------------------
'                 define Pins

      Wtdg Alias P3.2                                         'Watchdog MAX1232 Extern
      Driver_enable Alias P3.3                                'Enable Max3083 Tx (Rx = always on)
'-------------------------------------------------------------------------------
      Time = 4                                                'Wait Time for LCD Start Message
      Gosub Wait_sec
'-------------------------------------------------------------------------------
'*******************************************************************************
'Main
   Do

      Wtdg = 1                                                'pulse for Watchdogtimer
      Wtdg = 0
      Incr S_buf
      Printbin S_buf
      Time = 1
      Gosub Wait_sec

   Loop
   End
'*******************************************************************************
'-------------------------------------------------------------------------------
   Wait_sec:

      For A = 1 To Time                                       'Wait with watchdog pulse
          Wtdg = 1
          Wtdg = 0
          Waitms 250
          Wtdg = 1
          Wtdg = 0
          Waitms 250
          Wtdg = 1
          Wtdg = 0
          Waitms 250
          Wtdg = 1
          Wtdg = 0
          Waitms 250
      Next

   Return
'-------------------------------------------------------------------------------

 


For Rx:

Code:


' **********************************************************************
' **        Program name: LCD_2T  - Version : 1.0  21.12.2008         **
' **        Compiler : BASCOM 8051, ( V2.0.14.0)                      **
' **        Prozessor: 89S8252                                        **
' **        LCD 20 x 2 HD44780                                        **
' **                                                                  **
' **                                                                  **
' **                                                                  **
' **                                                                  **
' **                                                                  **
' **        Written by:  Sepp Bartl                                   **
' **********************************************************************

   $regfile = "89s8252.DAT"                                   'use the 89S8252.DAT file
   $baud = 19200                                              'Baud Rate
   $crystal = 22118400
'-------------------------------------------------------------------------------
'
  '$sim                                                       'only for Simulation
   $large                                                     'for large Programm
'-------------------------------------------------------------------------------
'                 Temporary Variables
      Dim A As Byte                                           'Temp for Wait_sec
      Dim Time As Byte                                        'Temp for Wait_sec Time
      Dim S_buf As Byte                                       'Temp for Uart
      Dim S_buf_old As Byte                                   'Temp for verify Uart old/new
      Dim Anzeige As String * 20                              'Temp for Display
'-------------------------------------------------------------------------------
'                 define Pins

      Wtdg Alias P3.5                                         'Watchdog MAX1232 Extern
      T1 Alias P3.2                                           'Left Key
      T2 Alias P3.3                                           'right Key
      Driver_enable Alias P3.6                                'Enable Max3083 Tx (Rx = always on)
      Led_ Alias P2.7                                         'LED low = aktive
      R_w Alias P2.5                                          'Read/Write LCD
      'LCD DB4 = P2.0                                         'LCD Display
      'LCD DB5 = P2.1                                         '  --//--
      'LCD DB6 = P2.2                                         '  --//--
      'LCD DB7 = P2.3                                         '  --//--
      'LCD E   = P2.4                                         '  --//--
      'LCD RS  = P2.6                                         '  --//--

'-------------------------------------------------------------------------------
   '        Init Lcd
      Config Lcdpin = Pin , Db4 = P2.0 , Db5 = P2.1 , Db6 = P2.2 , Db7 = P2.3
      Config Lcdpin = Pin , E = P2.4 , Rs = P2.6

      $asm                                                    'Assembler for LCD R/W
        MOV   C, r_w                                          'only with the Assembler-
        CLR   r_w                                             'routine run the Display
        JNC   continue                             .          'with connectet R/W PIN!!
        LJMP  0
      Continue:
      $end Asm

      Config Lcdbus = 4                                       'LCD im 4-Bit Modus
      Config Lcd = 20 * 2                                     'LCD 20 Zeichen,Zweizeilig
      Cursor Off
      Cls
'-------------------------------------------------------------------------------
      Locate 1 , 1
      Lcd " UART TEST   "
      Locate 2 , 1
      Lcd " BAUD = 19200 "
      Time = 3                                                'Wait 3 sec
      Gosub Wait_sec
      Cls
      Locate 1 , 1
      Lcd "S_buf= "
'-------------------------------------------------------------------------------
'     Interrupt
      On Serial Serial_rx                                     'Serial Interrupt on
      Enable Serial
      Enable Interrupts
'-------------------------------------------------------------------------------

'*******************************************************************************
'Main
   Do

      Wtdg = 1                                                'pulse for Watchdogtimer
      Wtdg = 0
      If S_buf <> S_buf_old Then                              'Write only by new Value to LCD
         Gosub Lcd_
      End If

   Loop
   End
'*******************************************************************************

'-------------------------------------------------------------------------------
   Serial_rx:
      Disable Serial
      Wtdg = 1                                                'pulse for Watchdogtimer
      Wtdg = 0
      S_buf = Inkey()                                         'get 8-Bit from Uart
      Scon.1 = 0                                              'I don't now Scon.1 = from Datasheet for Tx ??
      Enable Serial
   Return
'-------------------------------------------------------------------------------
   Lcd_:
      Locate 1 , 8
      Lcd S_buf ; "   "
      S_buf_old = S_buf
   Return
'-------------------------------------------------------------------------------

'-------------------------------------------------------------------------------

'-------------------------------------------------------------------------------
   Wait_sec:

      For A = 1 To Time                                       'Wait with watchdog pulse
          Wtdg = 1
          Wtdg = 0
          Waitms 250
          Wtdg = 1
          Wtdg = 0
          Waitms 250
          Wtdg = 1
          Wtdg = 0
          Waitms 250
          Wtdg = 1
          Wtdg = 0
          Waitms 250
      Next

   Return
'-------------------------------------------------------------------------------

 


The Rx Interrupt i have from MCS-Electronics AN #31

regards

Sepp
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum