SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne


      

                     ‫ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ‬

                  

                          




                          




                   Programming
      Embedded Systems Microcontroller

You Can Practice Microcontroller Programming Easily Now!
      WALID BALID, Tuesday, December 15, 2009
                                                                                              

Exp.26:Serial Communications RS232                                          

                                                                                                       
                                     RS232

                                                                                                     
                                                                  
                                                                                                  ·
                                                                                                   ·


              
     


     
                           Serial Communications                                                   Parallel
              Asynchronous                                        Synchronous                   Communications
·    Morse code telegraphy                           o I2C                                §   LPT
·    RS-232 (COM Port)                               o SPI                                §   ISA
·    RS-423                                          o PS2                                §   EISA
·    RS-485                                                                               §   VESA
                                                                                          §   ATA
·    Universal Serial Bus (USB)
                                                                                          §   SCSI
·    FireWire
                                                                                          §   PCI
·    Ethernet                                                                             §   PCMCIA
·    Fiber Channel1                                                                       §   IEEE-1284
·    InfiniBand2                                                                          §   IEEE-488
·    MIDI3
·    DMX5124
·    Serial ATA5
·    SpaceWire6
·    PCI Express
·    SONET and SDH7
·    T-1, E-18

1
  High-speed, for connecting computers to mass storage devices
2
  Very high speed, broadly comparable in scope to PCI
3
  Control of electronic musical instruments
4
  Control of theatrical lighting
5
  New replacement for parallel IDE
6
  Spacecraft communication network
7
  High speed telecommunication over optical fibers
8
  High speed telecommunication over copper pairs
                                          178                      
Practical Class 9                                                                         Programming Microcontrollers

                                                                               RS232
DTE9
                                                                                              DCE10




                                     
                                                  




       
                          TTL
                                    +3V ~ +25V"Space"“0” Ø
                                           .-3V ~ -25V"Mark"“1” Ø
                                                           .-3V ~ +3V“x” Ø

“GND”±25V
                                                                                  500mA




                                    
9
    Data Terminal Equipment (computer)
10
    Data Circuit-terminating Equipment (modem)
Faculty of Electrical and Electronic Eng.                          179              Automatic Control & Automation Dept.
                                                                               

                                                                  RS232
               Advantages                                  Disadvantages
         ü System-to-System       ×
               Chip-2-Chip
   50 ü                          .Chip-2-Sensor 
                     ×
                                                                    
  ±25 ü RS232<>TTL ×
                                                  
                     “0” , “1”     Single Master/Single Slave ×
    ü                                              ×




                   

                                                          RS232
  Serial Port “COM” RS232
                                                                                           
                                       Port                          Address
                                     COM1                             0x3F8
                                     COM2                             0x2F8
                                     COM3                             0x3E8
                                     COM4                             0x2E8

 DB-9PinCOMx




                           

                             180                      
Practical Class 9                                                                                     Programming Microcontrollers




                        
                                      1, 2, 3, …., 9

                 Pin          Name           Direction     Function                       Description
                  1            CD               In         Control                       Carrier Detect
                  2           RXD               In           Data                         Receive Data
                  3           TXD              Out           Data                        Transmit Data
                  4           DTR              Out         Control                    Data Terminal Ready
                  5           GND               ---        Ground                       System Ground
                  6           DSR               In         Control                      Data Set Ready
                  7           RTS              Out         Control                      Request to Send
                  8           CTS               In         Control                       Clear to Send
                  9            RI               In         Control                       Ring Indicator
                                                           : C D – C a r r i e r D e t e c t ( C o n t r o l s e n t fr o m D C E t o D T E )
 

                                                                  :RxD – Receive Data (Data sent from DCE to DTE)
                DTEDCE
Idle State, “1 or Negative”(Mark state, “0 or Positive”
                                                                                                      

                                                          :TxD – Transmit Data (Data sent from DTE to DCE)
                              DCEDTE
Idle State, “1 or Negative”Mark state, “0 or Positive”
                                                                                                       


 Faculty of Electrical and Electronic Eng.                        181                         Automatic Control & Automation Dept.
                                                                                                   

                                              : D T R – D a t a T e r m i n a l R e a d y ( C o n t r o l s e n t fr o m D T E t o D C E )
        DTE 
                                                                     DCE

                                                          : D S R – D a t a S e t R e a d y ( C o n t r o l s e n t fr o m D C E t o D T E )
                                DTEDCE
                                        “1”“0”

                                                   : R T S – R e q u e s t T o S e n d ( C o n t r o l s e n t fr o m D T E t o D C E )
      DTE  DCE
                                        
      “1” “0”
                                                                                                                      

                                                    : C T S – C l e a r T o S e n d ( C o n t r o l s e n t fr o m D C E t o D T E )
       DTE  
      DCE
                                                                                             
       “1”           “0” 
                                                                                                                        

                                                 : R I – R i n g I n d i c a t o r ( C o n t r o l s e n t fr o m D C E t o D T E )
         DTE
                                                                        

      “TxD ”              
                                                       “RxD ”




 


                                          182                               
Practical Class 9                                                                   Programming Microcontrollers

       Hardware handshaking     
    TxD, RxDRTS, CTS

 CTS Ø
                                                                                           
 RTS Ø
                                                RTS
              Ø
  ·
       RTS        ·
                          




                                                                       RS232
                        SPECIFICATIONS                                  RS232                    RS423
 Mode of Operation                                                 SINGLE-ENDED             SINGLE-ENDED
 Total Number of Drivers and Receivers on One Line                1DRIVER/1RECVR          1DRIVER/10RECVR
 Maximum Cable Length                                                   50 FT                  4000 FT
 Maximum Data Rate                                                     20kb/s                  100kb/s
 Maximum Driver Output Voltage                                          ±25V                      ±6V
 Driver Output Signal Level (Loaded Min.)     Loaded                 ±5V to ±15V                ±3.6V
 Driver Output Signal Level (Unloaded Max)    Unloaded                  ±25V                      ±6V
 Driver Load Impedance (Ohms)                                          3k to 7k                 >=450
 Max. Driver Current in High Z State          Power On                   N/A                     N/A
 Max. Driver Current in High Z State          Power Off             ±6mA @ ±2v                 ±100uA
 Slew Rate (Max.)                                                      30V/µS                 Adjustable
 Receiver Input Voltage Range                                           ±15V                     ±12V
 Receiver Input Sensitivity                                              ±3V                   ±200mV
 Receiver Input Resistance (Ohms)                                      3k to 7k                 4k min

                             
                                  Shield24AWG
                                                                                100Ω16PF/FT

Faculty of Electrical and Electronic Eng.                183                 Automatic Control & Automation Dept.
                                                                             

                          AsynchronizeSynchronize

 clock or strobe
                                    




        
 
                                                                              


Start Bit
Stop Bit
                  




      

                                                   




        
                       184                        
Practical Class 9                                                                   Programming Microcontrollers


                                                                 

     

                    Full-DuplexHalf-Duplex ü
                                                        6, 7 or 8bit  ü
                                                            Baud Rate ü
    Parity Bit         ü
                                                    Even or Odd
                                                             1, 1.5 or 2 ü

                                       Half-Duplex   
                                              
                                                                                                     
                                            Full-Duplex
                                                               

Parity Bit
                                                                      




                
“0” “Even”
                                                                 “1”
                       10110010 > Parity Bit = 0 | 10110110 > Parity Bit = 1
“0”“Odd”
                                                                  .“1”
                       10110010 > Parity Bit = 1 | 10110110 > Parity Bit = 0
Faculty of Electrical and Electronic Eng.                  185                Automatic Control & Automation Dept.
                                                                                    

N
        ASCII=127 N=7bit5, 6, 7 or 8bit




                  

                1, 1.5 or 2 Stop Bit




           

        Baud Rate 
                                                                   

                        300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, etc…
                                                              


                                                       =

                              


                                                   /        =
                                                                                                                   




                   

                               186                       
Practical Class 9                                                Programming Microcontrollers

                                                   RS232




 
Faculty of Electrical and Electronic Eng.   187            Automatic Control & Automation Dept.
                                                                              

                                                RS232
8250-UART
          
                                                         IOR, Input/Output Register/
COM1: 0x3F8 | COM2: 0x2F8
                     TxDRxD

                                
                                                     LCR, Line Control Register
COM1: 0x3FB | COM2: 0x2FB
                                                           




                                                             LSR, Line Status Register
COM1: 0x3FD | COM2: 0x2FD
 




                                                 MCR, Modem Control Register
COM1: 0x3FC | COM2: 0x2FC
  8250




                       188                         
Practical Class 9                                                                   Programming Microcontrollers

                                                             MSR, Modem Status Register
COM1: 0x3FE | COM2: 0x2FE
 “dxxx=1”  
                                                                                                  




                           

                                                    IER, Interrupt Enable Register
COM1: 0x3F9 | COM2: 0x2F9
       “1” Active    COM   
   COM2IRQ3COM1IRQ4




                                                                                                              

                                            IIR, Interrupt Identifcation R gi ster 
                                                                   i       e
COM1: 0x3FA | COM2: 0x2FA
                                                                      




                           

                                                                                                              
Faculty of Electrical and Electronic Eng.                 189                Automatic Control & Automation Dept.
                                                                              

 COM3 
                                                          




                

                                                                             
 8250  


                                                      1.8432 × 10
                                                                       "Divisor"1.8432MHZ

                                                  =
                                                      16 ×

                                                       Divisor9600bps

                                          1.8432 × 10   1.8432 × 10
                                      =               =             = 12
                                           16 ×          16 × 9600

                                UART8250D=12
                                                    LCRBit7=1 ·
                                    0x3F8LSB ·
                                   0x3F9MSB ·
                                                LCRBit7=0 ·

                           190                     
Practical Class 9                                                               Programming Microcontrollers

                                             VB, MVS2008.netCOM 

          ActiveX & OCX Components
Bios
                                                                  

                                    

         MSCOMM32.ocx“OCX”“MSComm”VB6
                  
                                                 COM

 System32
                                        VB6SP6

                     “Standard EXE”
                     VB6
                     “Enterprice Edition”
                                                                                                             




                     

Faculty of Electrical and Electronic Eng.                191              Automatic Control & Automation Dept.
                                                                             

  VB6 “Microsoft Visual Studio 2008”
             
SerialPort
 .(VB.net, C#.net or C++.net.net




                        
        SerialPort     
                                                                           VB6

                                                                               VB6
              
                                               (COM
                                                                         
                                                                       Test1/ProjRS232.vbp
                                                                     
                                                                     OutGoing
                                                                     Send Data
                                                                         
                                                                         
                                                                     InComing
                       192                        
Practical Class 9                                               Programming Microcontrollers

                                                                                
Private Sub Form_Load()
    MSComm1.CommPort = 1
    MSComm1.Settings = "9600,N,8,1"
    MSComm1.RThreshold = 1
    MSComm1.InputLen = 0
    MSComm1.InBufferCount = 0
End Sub

Private Sub cmdClear_Click()
    txtOutput.Text = ""
    txtInput.Text = ""
End Sub

Private Sub optCOM1_Click()
    MSComm1.CommPort = 1
End Sub

Private Sub optCOM2_Click()
    MSComm1.CommPort = 2
End Sub

Private Sub optOpen_Click()
    MSComm1.PortOpen = True
End Sub

Private Sub optClose_Click()
    MSComm1.PortOpen = Flase
End Sub

Private Sub optTXT_Click()
    MSComm1.InputMode = comInputModeText
End Sub

Private Sub optBIN_Click()
    MSComm1.InputMode = comInputModeBinary
End Sub

Private Sub cmdSendData_Click()
    MSComm1.Output = txtOutput.Text & Chr(13)
End Sub

Private Sub cmdExit_Click()
    If MSComm1.PortOpen = True Then MSComm1.PortOpen = Flase
    End
End Sub
Private Sub MSComm1_OnComm()
Static sBuff As String
    If MSComm1.CommEvent = comEvReceive Then
        If optBIN.Value = True Then
            sBuff = sBuff & StrConv(MSComm1.Input, vbUnicode)
            txtInput.Text = sBuff
        Else
            txtInput.Text = txtInput.Text & MSComm1.Input
        End If
    End If
End Sub
Faculty of Electrical and Electronic Eng.    193          Automatic Control & Automation Dept.
                                                                                   

                                                        :“MSComm”
MSComm1.CommPort = N
                                                                N
MSComm1.Settings = "Baud,Parity,Bits,Stop"
                                
MSComm1.RThreshold = n
 comEvReceive
   
                                                                  n=0
MSComm1.InputLen = n
   n=0      
                                                                                  
MSComm1.InBufferSize = n
                                                                         1~1024
MSComm1.OutBufferSize = n
                                                                           1~1024
MSComm1.InBufferCount = n
                                                                    
MSComm1.OutBufferCount = n
                                                                      
MSComm1.PortOpen = True | Flase
                                                                                        |
MSComm1.InputMode = comInputModeText | comInputModeBinary
         Input|
var = MSComm1.InPut
                                                                               
MSComm1.OutPut = var
                                                                                
MSComm1.CommEvent = Value
                                                            
             Value                                                                             
             comEvCD                                                           CD
             comEvCTS                                                        CTS
             comEvDSR                                                        DSR
             comEvRing                                                    RI
             comEvReceive              RThreshold
             comEvSend                    SThreshold
             comEvEOF                                            vbCrLf

MSComm1.DTREnable = True | Flase
 “0” “1”TrueDTR  |  | 
                                        “0”Flase
MSComm1.Handshaking = comNone|comRTS|comXOnXoff|comRTSXOnXOff
                           194                          
Practical Class 9                                                                    Programming Microcontrollers

                                                                          
 MSComm1.RTSEnable = True | Flase
 “1”TrueHardwareRTS | |
       “0”Flase“0”
                                                                                                                  
                                                                         
                                              
  Poling the Port  ü
              
                                                                                                    
 
                 Footer ByteHeader Byte
      OnComm() event    ü
  OnComm
                                                                                             

                                                 




                       
 Faculty of Electrical and Electronic Eng.                   195                Automatic Control & Automation Dept.
                                                                             

                                                                            Matlab
           Matlab   
                                       
                                                                                     
obj = serial('Port','PropertyName',PropertyValue,...)
Ser = serial('COM1','BaudRate',9600,'DataBits',8, 'Parity','non');
                                
fopen(obj)
fopen(Ser);
                                                                                     
fclose(obj)
fclose(Ser);
                                                                                  
delete(obj)
delete(Ser);
                                                                          
fprintf(fid, format, A, ...)
fprintf(Ser,'This is Test');
                                                    TXT
fwrite(fid, format, A, ...)
fwrite(Ser,4);
                                                      BIN
A = fscanf(fid, format)
A = fscanf(Ser);
                                                    TXT
A = fread(fid)
A = fread(Ser);
                                                      BIN
                                                                                                 
ser = serial('COM1','BaudRate',9600,'DataBits',8);
fopen(ser)

fprintf(ser,'This is Test')
A = fscanf(ser);
fprintf(ser,A)

for i=1:5
    fwrite(ser,i);
end
A = fread(ser);
fwrite(ser,A);

fclose(ser)
delete(ser)
clear ser
                         196                      
Practical Class 9                                                                   Programming Microcontrollers

                                                                                       TTL <> RS232
                                                               RS232    
                                                                  
                                                                 TTL    
                                                              Adapter

                                                                Max232   
                                                                                                      TTL<>RS232

                                                                                                                     

                                                                                                                     

                                                                                                                     

                                                                                                                     

  RS232 TTL<>RS232  
                                                   Max232UART
                                                                 




 
                                                                                                                     
                                                                                                                     
                                                                                                                     

      Faculty of Electrical and Electronic Eng.                       197           Automatic Control & Automation Dept.
                                                                   

  RS232 TTL<>RS232
                                      UART




 




                      198                     
Practical Class 9                                                                Programming Microcontrollers

  Exp.27: UART Interface                                   UART
                                                                                         
                                                                    UART
                                                                                          




 

                                                                                         
                                               TxD, RxDS312,4
                                                                                            
 RS232
                                                    .UART

  Faculty of Electrical and Electronic Eng.               199               Automatic Control & Automation Dept.
                                                                            

                         Universal Asynchronous Receiver and Transmiter Int erface  UART
                                                                        t
                
  TTL RS232
                        UART RS232

   MCU-MCU           
                                                                       MCU-PC




              
                AVR

                    TXD, RXDUART                ü
   TXD, RXDUSART                        ü
                                                                          XCK

                                                                    UART Frame Format
      RS232      UART        
                                                                 




 
      St: Start bit, always low.
      Data bits: (0 to 8).
      P : Parity bit (Can be odd or even)
      Sp: Stop bit, always high.
      IDLE: No transfers on the communication line (RxD or TxD), IDLE line is high.
                              200                      
Practical Class 9                                                                    Programming Microcontrollers

                                                             Baud Rate Register




                                     0 – 4095 UBRRH and UBRR UBRR 
                                                                                           

 9600bps 1Mhz UBRR


                                                              1000000
                                                                                                    

                                =                    −   =             − 1 = 5.510416 ≈ 6
                            ,
                                            ×                16 × 9600

9600
                
                                                               


0.5%
                                                                           5%

                                                                        

                                       [%]      =                        −     ×       %


                                                       

                                                      9600
                                                =            − 1 × 100% = 7.52%
                                        [%]
                                                    8928.571

               
                                                                                        

Faculty of Electrical and Electronic Eng.                    201               Automatic Control & Automation Dept.
                                                                                        

                                                                                               
                                                               
$baud = Var                                                 .UART0 (Hardware)
Baud     = Var                                   UART0 (Hardware)
$BAUD1 = var                                                .UART1 (Hardware)
Baud1      = Var                                 UART1 (Hardware)
Baud     #x , BaudRate                        x UART0 (Software)

Baud1 #x , BaudRate                           x UART1 (Software) 

Print Var ; "const"                                                        .UART0
Print [#channel,] Var; "const"                  .channel  UARTx
                                                               .UARTx
Printbin Var [; Varn]
                                                [; Varn]
                                                .channel  UARTx
Printbin #channel, Var [;Varn]
                                                [; Varn]
                                                   UART0RS232
                                                ["prompt"]
Input ["prompt"] , Var [,Varn]
                                                                        Var
                                              n=1,2…[,Varn]

Input #ch, Var [,Varn ]                     .ch UART0RS232
                                                 UART0RS232
Inputbin Var1 [,Var2]
                                                  [,Var2]
Inputbin #channel, Var1[,Var2]  .ch UARTxRS232

Inputhex ["prompt"],Var[,Varn]                 HEXUART0RS232

var = INKEY()                                  .UART0bufer Ascii
                                                                            f
                                            UARTx   bufer      Ascii   
                                                                          f
Var = Inkey(#channel)
                                                      .“0”  .channel 
                                             UART0   bufer       
                                                                                f
var = WAITKEY()
                                                                                                         Ascii
                                             UARTx bufer 
                                                                                   f
Var = Waitkey(#channel)
                                                                               Asciichannel 
                                             “1”   UART0    bufer   
                                                                                                         f
Var = Ischarwaiting()                       “0“
                                                                              

                         202                               
Practical Class 9                                                                              Programming Microcontrollers

                                                    “1”   UARTx   bufer   
                                                                                                               f
Var = Ischarwaiting(#channel)
                                                                              .“0”
                                                       UART1,2      
$Timeout = value                                   ‫ و‬Waitkey() Input  ،Input
                                                    bufer 
                                                                          f
Echo On|off                                                 Input|
                                                   compiler
Config Input = Term,
                                                    CR, LF, CRLF or LFCR 
Echo = Echo | Noecho
                                                                                                   Input
                                                   
$serialinput2lcd
                                                                       .Terminal 

Config Serialin|Serialin1|Serialin2|Serialin3 = Buffered, Size = Size
[, Bytematch = All|byte|none]
[, Cts = Pin, Rts = Pin, Threshold_full = Num, Threshold_empty = Num]

                      SRAM  Serialin Input Bufer 
                                                                                               f
SizeMAX= 255
§ SERIALIN : 1st UART Hardware Interface > UART0
§ SERIALIN1 : 2nd UART Hardware Interface > UART1
§ SERIALIN2 : 3rd UART Hardware Interface > UART2
§ SERIALIN3 : 4th UART Hardware Interface > UART3
 “ASCII” “Bytematch=byte”
                            
§    Serial0CharMatch (for SERIALIN or the 1st UART/UART0)
§    Serial1CharMatch (for SERIALIN1 or the 2nd UART/UART1)
§    Serial2CharMatch (for SERIALIN2 or the 3rd UART/UART2)
§    Serial3CharMatch (for SERIALIN3 or the 4th UART/UART3)
        “Bytematch=all”
§    Serial0ByteReceived (for SERIALIN or the 1st UART/UART0)
§    Serial1ByteReceived (for SERIALIN1 or the 2nd UART/UART1)
§    Serial2ByteReceived (for SERIALIN2 or the 3rd UART/UART2)
§    Serial3ByteReceived (for SERIALIN3 or the 4th UART/UART3)
                                      “Bytematch=none”
                                     “CTS”Cts = Pin
                                       “RTS”Rts = Pin
       “RTS=1”        Threshold_full = Num
                                                                                 
                Threshold_empty = Num
                                                                             “CTS=0”
                    “CTS-RTS”

Faculty of Electrical and Electronic Eng.                      203                     Automatic Control & Automation Dept.
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9

Contenu connexe

Tendances

20110224 saf cfip_brochure_en
20110224 saf cfip_brochure_en20110224 saf cfip_brochure_en
20110224 saf cfip_brochure_en
nezinamais
 
Advanced motion controls dzralte 060l080
Advanced motion controls dzralte 060l080Advanced motion controls dzralte 060l080
Advanced motion controls dzralte 060l080
Electromate
 
Technical s7889
Technical s7889Technical s7889
Technical s7889
huslen_du
 
Showing sound signals on VGA with using PMOD MIC
Showing sound signals on VGA with using PMOD MICShowing sound signals on VGA with using PMOD MIC
Showing sound signals on VGA with using PMOD MIC
ilker Şin
 
Bdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manualBdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manual
HARRY CHAN PUTRA
 
RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...
RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...
RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...
ASHOKKUMAR RAMAR
 

Tendances (20)

IMG-2102T Industrial Modbus Gateway
IMG-2102T  Industrial Modbus Gateway IMG-2102T  Industrial Modbus Gateway
IMG-2102T Industrial Modbus Gateway
 
Essential Guide Interfaces I/O 2010
Essential Guide Interfaces I/O 2010Essential Guide Interfaces I/O 2010
Essential Guide Interfaces I/O 2010
 
Folheto BCL 31, 32 e 34
Folheto BCL 31, 32 e 34Folheto BCL 31, 32 e 34
Folheto BCL 31, 32 e 34
 
30@30: April Newsletter
30@30: April Newsletter30@30: April Newsletter
30@30: April Newsletter
 
20110224 saf cfip_brochure_en
20110224 saf cfip_brochure_en20110224 saf cfip_brochure_en
20110224 saf cfip_brochure_en
 
Lika 30@30: products schedule
Lika 30@30: products scheduleLika 30@30: products schedule
Lika 30@30: products schedule
 
Advanced motion controls dzralte 060l080
Advanced motion controls dzralte 060l080Advanced motion controls dzralte 060l080
Advanced motion controls dzralte 060l080
 
Technical s7889
Technical s7889Technical s7889
Technical s7889
 
Showing sound signals on VGA with using PMOD MIC
Showing sound signals on VGA with using PMOD MICShowing sound signals on VGA with using PMOD MIC
Showing sound signals on VGA with using PMOD MIC
 
8051f044
8051f0448051f044
8051f044
 
analog to digital converter seminar
analog to digital converter seminaranalog to digital converter seminar
analog to digital converter seminar
 
Plc operation part 2
Plc operation part 2Plc operation part 2
Plc operation part 2
 
Siae datasheet
Siae datasheetSiae datasheet
Siae datasheet
 
Xb5 r batteryless wireless switch
Xb5 r batteryless wireless switchXb5 r batteryless wireless switch
Xb5 r batteryless wireless switch
 
Bdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manualBdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manual
 
PLC operation part 1
PLC operation part 1PLC operation part 1
PLC operation part 1
 
Rfid interface with lpc2148
Rfid interface with lpc2148 Rfid interface with lpc2148
Rfid interface with lpc2148
 
Direct Out Technologies Andiamo.MC
Direct Out Technologies Andiamo.MCDirect Out Technologies Andiamo.MC
Direct Out Technologies Andiamo.MC
 
Pdc 2 mark
Pdc   2 markPdc   2 mark
Pdc 2 mark
 
RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...
RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...
RFID PROJECTS ABSTRACT LIST-Rfid based access control and staff attendence ma...
 

En vedette

En vedette (8)

Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture6
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture3
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture7
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture4
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture11
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture...
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture8
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5
 

Similaire à Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9

FRDM-KL46Z_Hands-On_Presentation_v02
FRDM-KL46Z_Hands-On_Presentation_v02FRDM-KL46Z_Hands-On_Presentation_v02
FRDM-KL46Z_Hands-On_Presentation_v02
Libor GECNUK
 
Elm323 ds
Elm323 dsElm323 ds
Elm323 ds
sergio
 

Similaire à Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9 (20)

Batch 25(a)
Batch 25(a)Batch 25(a)
Batch 25(a)
 
EMBEDDED SYSTEM BASICS
EMBEDDED SYSTEM BASICSEMBEDDED SYSTEM BASICS
EMBEDDED SYSTEM BASICS
 
SIEMENS PXG3.L BACnet/IP Router
SIEMENS PXG3.L BACnet/IP RouterSIEMENS PXG3.L BACnet/IP Router
SIEMENS PXG3.L BACnet/IP Router
 
FRDM-KL46Z_Hands-On_Presentation_v02
FRDM-KL46Z_Hands-On_Presentation_v02FRDM-KL46Z_Hands-On_Presentation_v02
FRDM-KL46Z_Hands-On_Presentation_v02
 
Elm323 ds
Elm323 dsElm323 ds
Elm323 ds
 
Project_intership
Project_intershipProject_intership
Project_intership
 
Project_intership
Project_intershipProject_intership
Project_intership
 
Communication protocols
Communication protocolsCommunication protocols
Communication protocols
 
Chapter 3 esy
Chapter 3 esy Chapter 3 esy
Chapter 3 esy
 
Ofdm.pptx
Ofdm.pptxOfdm.pptx
Ofdm.pptx
 
interfaces.pptx
interfaces.pptxinterfaces.pptx
interfaces.pptx
 
Ch09 system administration
Ch09 system administration Ch09 system administration
Ch09 system administration
 
Computer Interfaces
Computer Interfaces Computer Interfaces
Computer Interfaces
 
UNIT-2 PPT Data link layer.pptx
UNIT-2 PPT Data link layer.pptxUNIT-2 PPT Data link layer.pptx
UNIT-2 PPT Data link layer.pptx
 
Galil rio catalog
Galil rio catalogGalil rio catalog
Galil rio catalog
 
Basics Of Embedded Systems
Basics Of Embedded SystemsBasics Of Embedded Systems
Basics Of Embedded Systems
 
Parth xyz
Parth xyzParth xyz
Parth xyz
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communication
 
Wireless agro automation system
Wireless agro automation systemWireless agro automation system
Wireless agro automation system
 
ACR128 product presentation by Advanced Card Systems Ltd.
ACR128 product presentation by Advanced Card Systems Ltd.ACR128 product presentation by Advanced Card Systems Ltd.
ACR128 product presentation by Advanced Card Systems Ltd.
 

Dernier

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9

  • 1.    ‫ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ‬     Programming Embedded Systems Microcontroller You Can Practice Microcontroller Programming Easily Now! WALID BALID, Tuesday, December 15, 2009
  • 2.     Exp.26:Serial Communications RS232      RS232       ·  ·                        Serial Communications Parallel Asynchronous Synchronous   Communications · Morse code telegraphy o I2C § LPT · RS-232 (COM Port) o SPI § ISA · RS-423 o PS2 § EISA · RS-485 § VESA § ATA · Universal Serial Bus (USB) § SCSI · FireWire § PCI · Ethernet § PCMCIA · Fiber Channel1 § IEEE-1284 · InfiniBand2 § IEEE-488 · MIDI3 · DMX5124 · Serial ATA5 · SpaceWire6 · PCI Express · SONET and SDH7 · T-1, E-18 1 High-speed, for connecting computers to mass storage devices 2 Very high speed, broadly comparable in scope to PCI 3 Control of electronic musical instruments 4 Control of theatrical lighting 5 New replacement for parallel IDE 6 Spacecraft communication network 7 High speed telecommunication over optical fibers 8 High speed telecommunication over copper pairs  178 
  • 3. Practical Class 9 Programming Microcontrollers  RS232 DTE9  DCE10        TTL  +3V ~ +25V"Space"“0” Ø  .-3V ~ -25V"Mark"“1” Ø  .-3V ~ +3V“x” Ø “GND”±25V  500mA   9 Data Terminal Equipment (computer) 10 Data Circuit-terminating Equipment (modem) Faculty of Electrical and Electronic Eng. 179 Automatic Control & Automation Dept.
  • 4.      RS232  Advantages  Disadvantages        ü System-to-System       ×    Chip-2-Chip  50 ü .Chip-2-Sensor           ×     ±25 ü RS232<>TTL ×   “0” , “1”  Single Master/Single Slave ×  ü  ×    RS232 Serial Port “COM” RS232   Port Address COM1 0x3F8 COM2 0x2F8 COM3 0x3E8 COM4 0x2E8  DB-9PinCOMx    180 
  • 5. Practical Class 9 Programming Microcontrollers    1, 2, 3, …., 9 Pin Name Direction Function Description 1 CD In Control Carrier Detect 2 RXD In Data Receive Data 3 TXD Out Data Transmit Data 4 DTR Out Control Data Terminal Ready 5 GND --- Ground System Ground 6 DSR In Control Data Set Ready 7 RTS Out Control Request to Send 8 CTS In Control Clear to Send 9 RI In Control Ring Indicator   : C D – C a r r i e r D e t e c t ( C o n t r o l s e n t fr o m D C E t o D T E )   :RxD – Receive Data (Data sent from DCE to DTE)  DTEDCE Idle State, “1 or Negative”(Mark state, “0 or Positive”   :TxD – Transmit Data (Data sent from DTE to DCE)  DCEDTE Idle State, “1 or Negative”Mark state, “0 or Positive”   Faculty of Electrical and Electronic Eng. 181 Automatic Control & Automation Dept.
  • 6.     : D T R – D a t a T e r m i n a l R e a d y ( C o n t r o l s e n t fr o m D T E t o D C E )   DTE   DCE : D S R – D a t a S e t R e a d y ( C o n t r o l s e n t fr o m D C E t o D T E )  DTEDCE  “1”“0” : R T S – R e q u e s t T o S e n d ( C o n t r o l s e n t fr o m D T E t o D C E ) DTE  DCE   “1” “0”   : C T S – C l e a r T o S e n d ( C o n t r o l s e n t fr o m D C E t o D T E )  DTE   DCE    “1”           “0”   : R I – R i n g I n d i c a t o r ( C o n t r o l s e n t fr o m D C E t o D T E )    DTE   “TxD ”                “RxD ”    182 
  • 7. Practical Class 9 Programming Microcontrollers        Hardware handshaking       TxD, RxDRTS, CTS  CTS Ø   RTS Ø RTS  Ø  ·        RTS        ·   RS232 SPECIFICATIONS RS232 RS423 Mode of Operation SINGLE-ENDED SINGLE-ENDED Total Number of Drivers and Receivers on One Line 1DRIVER/1RECVR 1DRIVER/10RECVR Maximum Cable Length 50 FT 4000 FT Maximum Data Rate 20kb/s 100kb/s Maximum Driver Output Voltage ±25V ±6V Driver Output Signal Level (Loaded Min.) Loaded ±5V to ±15V ±3.6V Driver Output Signal Level (Unloaded Max) Unloaded ±25V ±6V Driver Load Impedance (Ohms) 3k to 7k >=450 Max. Driver Current in High Z State Power On N/A N/A Max. Driver Current in High Z State Power Off ±6mA @ ±2v ±100uA Slew Rate (Max.) 30V/µS Adjustable Receiver Input Voltage Range ±15V ±12V Receiver Input Sensitivity ±3V ±200mV Receiver Input Resistance (Ohms) 3k to 7k 4k min  Shield24AWG 100Ω16PF/FT Faculty of Electrical and Electronic Eng. 183 Automatic Control & Automation Dept.
  • 8.      AsynchronizeSynchronize   clock or strobe         Start Bit Stop Bit         184 
  • 9. Practical Class 9 Programming Microcontrollers     Full-DuplexHalf-Duplex ü 6, 7 or 8bit  ü Baud Rate ü     Parity Bit         ü Even or Odd  1, 1.5 or 2 ü       Half-Duplex                    Full-Duplex   Parity Bit     “0” “Even” “1” 10110010 > Parity Bit = 0 | 10110110 > Parity Bit = 1 “0”“Odd”  .“1” 10110010 > Parity Bit = 1 | 10110110 > Parity Bit = 0 Faculty of Electrical and Electronic Eng. 185 Automatic Control & Automation Dept.
  • 10.     N  ASCII=127 N=7bit5, 6, 7 or 8bit   1, 1.5 or 2 Stop Bit           Baud Rate    300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, etc…   =   / =      186 
  • 11. Practical Class 9 Programming Microcontrollers  RS232   Faculty of Electrical and Electronic Eng. 187 Automatic Control & Automation Dept.
  • 12.      RS232 8250-UART   IOR, Input/Output Register/ COM1: 0x3F8 | COM2: 0x2F8  TxDRxD   LCR, Line Control Register COM1: 0x3FB | COM2: 0x2FB   LSR, Line Status Register COM1: 0x3FD | COM2: 0x2FD   MCR, Modem Control Register COM1: 0x3FC | COM2: 0x2FC  8250  188 
  • 13. Practical Class 9 Programming Microcontrollers MSR, Modem Status Register COM1: 0x3FE | COM2: 0x2FE  “dxxx=1”        IER, Interrupt Enable Register COM1: 0x3F9 | COM2: 0x2F9        “1” Active    COM     COM2IRQ3COM1IRQ4   IIR, Interrupt Identifcation R gi ster  i e COM1: 0x3FA | COM2: 0x2FA      Faculty of Electrical and Electronic Eng. 189 Automatic Control & Automation Dept.
  • 14.      COM3         8250   1.8432 × 10  "Divisor"1.8432MHZ = 16 ×  Divisor9600bps 1.8432 × 10 1.8432 × 10 = = = 12 16 × 16 × 9600  UART8250D=12  LCRBit7=1 ·  0x3F8LSB ·  0x3F9MSB ·  LCRBit7=0 ·  190 
  • 15. Practical Class 9 Programming Microcontrollers  VB, MVS2008.netCOM             ActiveX & OCX Components Bios      MSCOMM32.ocx“OCX”“MSComm”VB6   COM  System32  VB6SP6  “Standard EXE”  VB6  “Enterprice Edition”    Faculty of Electrical and Electronic Eng. 191 Automatic Control & Automation Dept.
  • 16.       VB6 “Microsoft Visual Studio 2008”  SerialPort  .(VB.net, C#.net or C++.net.net           SerialPort       VB6  VB6                 (COM       Test1/ProjRS232.vbp  OutGoing Send Data            InComing  192 
  • 17. Practical Class 9 Programming Microcontrollers    Private Sub Form_Load() MSComm1.CommPort = 1 MSComm1.Settings = "9600,N,8,1" MSComm1.RThreshold = 1 MSComm1.InputLen = 0 MSComm1.InBufferCount = 0 End Sub Private Sub cmdClear_Click() txtOutput.Text = "" txtInput.Text = "" End Sub Private Sub optCOM1_Click() MSComm1.CommPort = 1 End Sub Private Sub optCOM2_Click() MSComm1.CommPort = 2 End Sub Private Sub optOpen_Click() MSComm1.PortOpen = True End Sub Private Sub optClose_Click() MSComm1.PortOpen = Flase End Sub Private Sub optTXT_Click() MSComm1.InputMode = comInputModeText End Sub Private Sub optBIN_Click() MSComm1.InputMode = comInputModeBinary End Sub Private Sub cmdSendData_Click() MSComm1.Output = txtOutput.Text & Chr(13) End Sub Private Sub cmdExit_Click() If MSComm1.PortOpen = True Then MSComm1.PortOpen = Flase End End Sub Private Sub MSComm1_OnComm() Static sBuff As String If MSComm1.CommEvent = comEvReceive Then If optBIN.Value = True Then sBuff = sBuff & StrConv(MSComm1.Input, vbUnicode) txtInput.Text = sBuff Else txtInput.Text = txtInput.Text & MSComm1.Input End If End If End Sub Faculty of Electrical and Electronic Eng. 193 Automatic Control & Automation Dept.
  • 18.      :“MSComm” MSComm1.CommPort = N  N MSComm1.Settings = "Baud,Parity,Bits,Stop"  MSComm1.RThreshold = n  comEvReceive   n=0 MSComm1.InputLen = n    n=0         MSComm1.InBufferSize = n 1~1024 MSComm1.OutBufferSize = n 1~1024 MSComm1.InBufferCount = n  MSComm1.OutBufferCount = n  MSComm1.PortOpen = True | Flase | MSComm1.InputMode = comInputModeText | comInputModeBinary Input| var = MSComm1.InPut  MSComm1.OutPut = var  MSComm1.CommEvent = Value   Value   comEvCD CD comEvCTS   CTS comEvDSR   DSR comEvRing RI comEvReceive   RThreshold comEvSend   SThreshold comEvEOF   vbCrLf MSComm1.DTREnable = True | Flase  “0” “1”TrueDTR  |  |  “0”Flase MSComm1.Handshaking = comNone|comRTS|comXOnXoff|comRTSXOnXOff  194 
  • 19. Practical Class 9 Programming Microcontrollers   MSComm1.RTSEnable = True | Flase  “1”TrueHardwareRTS | |  “0”Flase“0”         Poling the Port  ü                   Footer ByteHeader Byte       OnComm() event    ü   OnComm      Faculty of Electrical and Electronic Eng. 195 Automatic Control & Automation Dept.
  • 20.      Matlab            Matlab        obj = serial('Port','PropertyName',PropertyValue,...) Ser = serial('COM1','BaudRate',9600,'DataBits',8, 'Parity','non');   fopen(obj) fopen(Ser);   fclose(obj) fclose(Ser);   delete(obj) delete(Ser);   fprintf(fid, format, A, ...) fprintf(Ser,'This is Test'); TXT fwrite(fid, format, A, ...) fwrite(Ser,4); BIN A = fscanf(fid, format) A = fscanf(Ser); TXT A = fread(fid) A = fread(Ser); BIN   ser = serial('COM1','BaudRate',9600,'DataBits',8); fopen(ser) fprintf(ser,'This is Test') A = fscanf(ser); fprintf(ser,A) for i=1:5 fwrite(ser,i); end A = fread(ser); fwrite(ser,A); fclose(ser) delete(ser) clear ser  196 
  • 21. Practical Class 9 Programming Microcontrollers  TTL <> RS232   RS232               TTL      Adapter    Max232     TTL<>RS232         RS232 TTL<>RS232    Max232UART           Faculty of Electrical and Electronic Eng. 197 Automatic Control & Automation Dept.
  • 22.     RS232 TTL<>RS232  UART    198 
  • 23. Practical Class 9 Programming Microcontrollers Exp.27: UART Interface UART     UART         TxD, RxDS312,4   RS232 .UART Faculty of Electrical and Electronic Eng. 199 Automatic Control & Automation Dept.
  • 24.      Universal Asynchronous Receiver and Transmiter Int erface  UART t                TTL RS232  UART RS232  MCU-MCU             MCU-PC     AVR TXD, RXDUART ü  TXD, RXDUSART ü  XCK  UART Frame Format RS232      UART             St: Start bit, always low. Data bits: (0 to 8). P : Parity bit (Can be odd or even) Sp: Stop bit, always high. IDLE: No transfers on the communication line (RxD or TxD), IDLE line is high.  200 
  • 25. Practical Class 9 Programming Microcontrollers Baud Rate Register  0 – 4095 UBRRH and UBRR UBRR    9600bps 1Mhz UBRR 1000000   = − = − 1 = 5.510416 ≈ 6 , × 16 × 9600 9600                     0.5%  5%   [%] = − × %   9600 = − 1 × 100% = 7.52% [%] 8928.571                   Faculty of Electrical and Electronic Eng. 201 Automatic Control & Automation Dept.
  • 26.             $baud = Var .UART0 (Hardware) Baud = Var  UART0 (Hardware) $BAUD1 = var .UART1 (Hardware) Baud1 = Var  UART1 (Hardware) Baud #x , BaudRate x UART0 (Software) Baud1 #x , BaudRate x UART1 (Software)  Print Var ; "const"  .UART0 Print [#channel,] Var; "const" .channel  UARTx .UARTx Printbin Var [; Varn]  [; Varn] .channel  UARTx Printbin #channel, Var [;Varn]  [; Varn]  UART0RS232  ["prompt"] Input ["prompt"] , Var [,Varn]  Var  n=1,2…[,Varn] Input #ch, Var [,Varn ]  .ch UART0RS232  UART0RS232 Inputbin Var1 [,Var2]  [,Var2] Inputbin #channel, Var1[,Var2]  .ch UARTxRS232 Inputhex ["prompt"],Var[,Varn]  HEXUART0RS232 var = INKEY()  .UART0bufer Ascii f UARTx   bufer      Ascii    f Var = Inkey(#channel) .“0”  .channel   UART0   bufer        f var = WAITKEY()   Ascii  UARTx bufer  f Var = Waitkey(#channel)   Asciichannel   “1”   UART0    bufer    f Var = Ischarwaiting() “0“    202 
  • 27. Practical Class 9 Programming Microcontrollers  “1”   UARTx   bufer    f Var = Ischarwaiting(#channel)  .“0”    UART1,2       $Timeout = value ‫ و‬Waitkey() Input  ،Input   bufer  f Echo On|off  Input| compiler Config Input = Term,  CR, LF, CRLF or LFCR  Echo = Echo | Noecho  Input  $serialinput2lcd  .Terminal  Config Serialin|Serialin1|Serialin2|Serialin3 = Buffered, Size = Size [, Bytematch = All|byte|none] [, Cts = Pin, Rts = Pin, Threshold_full = Num, Threshold_empty = Num]   SRAM  Serialin Input Bufer   f SizeMAX= 255 § SERIALIN : 1st UART Hardware Interface > UART0 § SERIALIN1 : 2nd UART Hardware Interface > UART1 § SERIALIN2 : 3rd UART Hardware Interface > UART2 § SERIALIN3 : 4th UART Hardware Interface > UART3  “ASCII” “Bytematch=byte”   § Serial0CharMatch (for SERIALIN or the 1st UART/UART0) § Serial1CharMatch (for SERIALIN1 or the 2nd UART/UART1) § Serial2CharMatch (for SERIALIN2 or the 3rd UART/UART2) § Serial3CharMatch (for SERIALIN3 or the 4th UART/UART3)  “Bytematch=all” § Serial0ByteReceived (for SERIALIN or the 1st UART/UART0) § Serial1ByteReceived (for SERIALIN1 or the 2nd UART/UART1) § Serial2ByteReceived (for SERIALIN2 or the 3rd UART/UART2) § Serial3ByteReceived (for SERIALIN3 or the 4th UART/UART3)  “Bytematch=none”  “CTS”Cts = Pin “RTS”Rts = Pin        “RTS=1”        Threshold_full = Num                  Threshold_empty = Num  “CTS=0” “CTS-RTS” Faculty of Electrical and Electronic Eng. 203 Automatic Control & Automation Dept.