SlideShare una empresa de Scribd logo
1 de 16
Descargar para leer sin conexión


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

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

                   

                          




                          




                   Programming
      Embedded Systems Microcontroller

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

Essential Instructions in Bascom-AVR                        Bascom-AVR

                                                                        ·
                                                             
$regfile = "m128def.dat"                                              ATmega128
$crystal = 1000000                                           
$baud = 9600                                                       


                                                                               ·
                                                             
Wait value                                                          Value
Waitms value                                                    Value
Waitus value                                                 Value


                                      / ·
                                                         
Config Portc = Output                                                                C
Config Portc.5 = Output                                               C5
Config Portc = Input                                                                 C
Config Pinc.5 = Input                                                 C5
Portc = 255                                                                   C
Pinc.5 = 1                                                     C5
Pinc.5 = 0                                                C5
Portc = &B11110000                                                       C
                                              /
Config Portc = &B11110000
                                                             10
Leds Alias Portd                               LedsD
Leds Alias Portd.5                              Led5


     

                                                                               


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

                                             Set/Reset ·
                                                        
Set bit                                               /
Reset bit                                              /
Toggle bit                                     /
                                                                                                                 
                                                                               ·
                                                        
If Expression1 Then
   Statements1                                          
   ...
Elseif Expression2 Then                                                                         
   Statements2
                                                                           11
   ...
Else                                                                    22
   Statements3
   ...                                                                             3
End If
SELECT CASE var
                                                        
     Case Test1 : Statements1                                                           
     Case Test2 : Statements2                                         1 var = Test1
     Case Else : Statements3                                          2 var = Test2
                                                                                     3
END SELECT


                                                                                 ·
                                                        
Do
                                                      
     Statements
                                                     
Loop [until Expression]
While Condition

     Statements                                              
Wend
For Var = Start To End [step Value]                    
     Statements                               End  Start
Next Var                                                                                      .step
Exit For                                                                          For
Exit Do                                                                           Do
Exit While                                                                     While

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

                                       SRAM ·
                                               
Dim Var1 As Bit                                               0 or 1
Dim Var2 As Byte                                             0 to 255
Dim Var3 As Integer                                  -32,768 to +32,767
Dim Var4 As Word                                           0 to 65535
Dim Var5 As Long                            -2147483648 to 2147483647
Dim Var6 As Single                           1.5 x 10^–45 to 3.4 x 10^38
Dim Var7 As Double                                               
Dim Var8 As String * 1                      *   chr_num

Dim Array(8) As Byte                                                  
Const Symbol = Numconst
Ex. Const Pi = 3.14159265358979
                                                                         
Const Symbol = Stringconst
Ex. Const S = "TEST"                                                    
Const Symbol = Expression
Ex. Const E =(b1 * 3) + 2
                                                                          
Local Var As Type                      


                                                            ·
                                               
                                           Px.y     
Debounce Px.y , state , label , Sub
Ex. Debounce Key1 , 0 , Sw1 , Sub
                                       state
                                            label
                                       Debounce 
Config Debounce = time
                                                            
Bitwait x , Set/reset                           
Ex. Bitwait Pinb.7 , reset              




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

      Exp.1: Scrolling LEDs                                                


                                                                                                     
         
                                                                                                     




 
                                                                                                      
                                                                                         JP9, JP10
                                                                                                     
       
                                                                                              .LEDs7         -1
                                                                                         -2
                                                         -3
      Faculty of Electrical and Electronic Eng.                     45                Automatic Control & Automation Dept.
                                                                         

                                                   -4
                                                                                 
$regfile = "m128def.dat"
$crystal = 1000000                                                
'-----------------------
Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.3 = Output
                                                                
Config Porte.4 = Output
Config Porte.5 = Output
Config Porte.6 = Output
Config Porte.7 = Output
'-----------------------
Leds1 Alias Portd                            
Leds2 Alias Porte                                                     
'-----------------------
Dim I As Byte , J As Byte                                      
'-----------------------
Do
   For I = 0 To 3
      J = I + 4                              
      Set Leds1.i
      Set Leds2.j                                                    
      Wait 1
   Next I

   For I = 3 To 0 Step -1
      J = I + 4
      Reset Leds1.i                          
      Reset Leds2.j
      Wait 1                                                   
   Next I
Loop
End
                                                                                                        




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

      Exp.2: Tact Switches                                                  


                                                                                            
                                     
                                                                                            




 
                                                                                             
                                                                                 JP6, JP8
                                                                                                              
      Faculty of Electrical and Electronic Eng.             47               Automatic Control & Automation Dept.
                                                                                            

                                                                                                      
                                         
                                   GNDJP6, JP8 -1
                                                       VCC JP6, GNDJP8 -2

                                                           GNDJP6, JP8
$regfile = "m128def.dat"
$crystal = 1000000                                                                    
$baud = 4800
'-----------------------
Config Debounce = 150                                             
Config    Pind.0       =   Input
Config    Pind.1       =   Input
Config    Pind.2       =   Input
Config    Pind.3       =   Input
                                                                                   
Config    Pine.4       =   Input
Config    Pine.5       =   Input
Config    Pine.6       =   Input
Config    Pine.7       =   Input

Portd.0 = 1 : Portd.1 = 1
Portd.2 = 1 : Portd.3 = 1
Porte.4 = 1 : Porte.5 = 1
                                                                               
Porte.6 = 1 : Porte.7 = 1
'-----------------------
Key1 Alias Pind.0
Key2 Alias Pind.1
Key3 Alias Pind.2
Key4 Alias Pind.3                                                
Key5 Alias Pine.4
                                                                                       
Key6 Alias Pine.5
Key7 Alias Pine.6
Key8 Alias Pine.7
'-----------------------

Do
     Debounce     Key1     ,   0   ,   Sw1   ,   Sub
     Debounce     Key2     ,   0   ,   Sw2   ,   Sub
     Debounce     Key3     ,   0   ,   Sw3   ,   Sub
     Debounce     Key4     ,   0   ,   Sw4   ,   Sub                            
     Debounce     Key5     ,   0   ,   Sw5   ,   Sub
     Debounce     Key6     ,   0   ,   Sw6   ,   Sub                          
     Debounce     Key7     ,   0   ,   Sw7   ,   Sub
     Debounce     Key8     ,   0   ,   Sw8   ,   Sub

Waitms 200

Loop
End
'-----------------------


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

Sw1:                                                                  
   Print "Switch(1)              is pressed!"
Return                                                
'/------------
Sw2:                                                         
   Print "Switch(2)              is pressed!"
Return
'/------------
Sw3:
   Print "Switch(3)              is pressed!"
Return
'/------------
Sw4:
   Print "Switch(4)              is pressed!"
Return
'/------------
Sw5:
   Print "Switch(5)              is pressed!"
Return
'/------------
Sw6:
   Print "Switch(6)              is pressed!"
Return
'/------------
Sw7:
   Print "Switch(7)              is pressed!"
Return
'/------------
Sw8:
   Print "Switch(8)              is pressed!"
Return




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

                                          VCC JP8‫ و‬GNDJP6,
   PortD
                                                         S6




 
                                                                                                                     
      $regfile = "m128def.dat"
      $crystal = 1000000                                                           
      $baud = 4800
      '-----------------------
      Config Debounce = 150                                      
      Config    Pind.0       =   Input
      Config    Pind.1       =   Input
      Config    Pind.2       =   Input
      Config    Pind.3       =   Input
                                                                                
      Config    Pine.4       =   Input
      Config    Pine.5       =   Input
      Config    Pine.6       =   Input
      Config    Pine.7       =   Input


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

Portd.0 = 0 : Portd.1 = 0
Portd.2 = 0 : Portd.3 = 0                             Portd
Porte.4 = 1 : Porte.5 = 1
Porte.6 = 1 : Porte.7 = 1                             PortE
'-----------------------
Key1 Alias Pind.0
Key2 Alias Pind.1
Key3 Alias Pind.2
Key4 Alias Pind.3                           
Key5 Alias Pine.4
Key6 Alias Pine.5                                                     
Key7 Alias Pine.6
Key8 Alias Pine.7
'-----------------------
Do
   Debounce Key1 , 0 , Sw1 , Sub
   Debounce Key2 , 0 , Sw2 , Sub
   Debounce Key3 , 0 , Sw3 , Sub
   Debounce Key4 , 0 , Sw4 , Sub
   Debounce Key5 , 0 , Sw5 , Sub                              
   Debounce Key6 , 0 , Sw6 , Sub                             
   Debounce Key7 , 0 , Sw7 , Sub
   Debounce Key8 , 0 , Sw8 , Sub
Waitms 200
Loop
End
'-----------------------
Sw1:
   Print "Switch(1) is pressed!"
Return
'/------------
Sw2:
   Print "Switch(2) is pressed!"
Return
'/------------
Sw3:
   Print "Switch(3) is pressed!"
Return
'/------------
Sw4:
   Print "Switch(4) is pressed!"
Return
'/------------                                                    
Sw5:
   Print "Switch(5) is pressed!"                  
Return                                                   
'/------------
Sw6:
   Print "Switch(6) is pressed!"
Return
'/------------
Sw7:
   Print "Switch(7) is pressed!"
Return
'/------------
Sw8:
   Print "Switch(8) is pressed!"
Return


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

      Exp.3: Expansion Connectors                         /


                                                                                            
            /–
                                                                                             




 
                                                                                             
                                  –JP1~ JP6
                                                                                             
  
                 S
                                     VCC           -1
                                 GND             -2


                                                                                                                  
                                                                                                                  
                                                                                                                  


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

 :GND  ·
$regfile = "m128def.dat"
$crystal = 1000000                                                      
$baud = 4800
'-----------------------
Config Porte = Input
Config Portb = Input
Config Portd = Input                                                 
Config Portc = Input
Config Porta = Input
'-----------------------
Porta = 255
Portb = 255
Portc = 255                                                  
Portd = 255
Porte = 255
'-----------------------
Pa_value Alias Pina
Pb_value Alias Pinb                                
Pc_value Alias Pinc
Pd_value Alias Pind                                                      
Pe_value Alias Pine
'-----------------------
Do
   Print "PA= " ; Pa_value
      Print "PB= " ; Pb_value
         Print "PC= " ; Pc_value
             Print "PD= " ; Pd_value                              
                Print "PE= " ; Pe_value                  
                   Print "------------"
   Wait 1
Loop
End
'-----------------------                                                                                       




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

   :VCC ·
$regfile = "m128def.dat"
$crystal = 1000000                                                        
$baud1 = 4800
'-----------------------
Config Porte = Input
Config Portb = Input
Config Portd = Input                                                   
Config Portc = Input
Config Porta = Input
'-----------------------
Porta = 0
Portb = 0
Portc = 0                                                    
Portd = 0
Porte = 0
'-----------------------
Pa_value Alias Pina
Pb_value Alias Pinb                                     
Pc_value Alias Pinc
Pd_value Alias Pind                                                     
Pe_value Alias Pine
'-----------------------
Open "com2:" For Binary As #1

Do
   Print #1 , "PA= " ; Pa_value
      Print #1 , "PB= " ; Pb_value
         Print #1 , "PC= " ; Pc_value
            Print #1 , "PD= " ; Pd_value                            
               Print #1 , "PE= " ; Pe_value
                  Print #1 , "-----------"
                                                           
   Wait 1
Loop

Close #1
End
'-----------------------




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

      Exp.4: Controlling Relay (On/Of)
                                    f                                   


                                                                                                    
                                                   
                                                                                                    




 
                                                                                                     
                                                                                   JP22~ JP21
                                                                                                                      
      Faculty of Electrical and Electronic Eng.                   55                 Automatic Control & Automation Dept.
                                                                                  

                                                                                           
     Portd.7  Portd.5       
                                                                       K2K1
                                                                                       
$regfile = "m128def.dat"
$crystal = 1000000                                                              
'-----------------------
Config Portd.5 = Output                                                      
Config Portd.7 = Output
'-----------------------
Relay1 Alias Portd.5                                          
Relay2 Alias Portd.7                                                         
'-----------------------
Dim I As Byte                                                                
'-----------------------
   For I = 0 To 9
      Set Relay1
      Wait 2
      Set Relay2

         Wait 2
                                                                          
      Reset Relay1
      Wait 2
      Reset Relay2
   Next I
End
'-----------------------




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

Más contenido relacionado

La actualidad más candente

3相ACモーターのスパイスモデルの概要
3相ACモーターのスパイスモデルの概要3相ACモーターのスパイスモデルの概要
3相ACモーターのスパイスモデルの概要Tsuyoshi Horigome
 
Cn3210001005
Cn3210001005Cn3210001005
Cn3210001005IJMER
 
Concept Kit:PWM Buck Converter Transients Model
Concept Kit:PWM Buck Converter Transients ModelConcept Kit:PWM Buck Converter Transients Model
Concept Kit:PWM Buck Converter Transients ModelTsuyoshi Horigome
 
DRV401AIDWPG4
DRV401AIDWPG4DRV401AIDWPG4
DRV401AIDWPG4spicepark
 
ICE Presentation: Integrated Component Characterization Environment
ICE Presentation: Integrated Component Characterization EnvironmentICE Presentation: Integrated Component Characterization Environment
ICE Presentation: Integrated Component Characterization EnvironmentNMDG NV
 
A3918 low voltage dc motor driver allegro datasheet[1]
A3918 low voltage dc motor driver allegro   datasheet[1]A3918 low voltage dc motor driver allegro   datasheet[1]
A3918 low voltage dc motor driver allegro datasheet[1]putchi56
 
Electronic circuit design lab manual
Electronic circuit design lab manualElectronic circuit design lab manual
Electronic circuit design lab manualawais ahmad
 
SPICE MODEL of uPC78L10J in SPICE PARK
SPICE MODEL of uPC78L10J in SPICE PARKSPICE MODEL of uPC78L10J in SPICE PARK
SPICE MODEL of uPC78L10J in SPICE PARKTsuyoshi Horigome
 
Programming And Controlling Puma Arms
Programming And Controlling Puma ArmsProgramming And Controlling Puma Arms
Programming And Controlling Puma Arms블로그코디
 
SPICE MODEL of uPC2407A in SPICE PARK
SPICE MODEL of uPC2407A in SPICE PARKSPICE MODEL of uPC2407A in SPICE PARK
SPICE MODEL of uPC2407A in SPICE PARKTsuyoshi Horigome
 

La actualidad más candente (20)

3相ACモーターのスパイスモデルの概要
3相ACモーターのスパイスモデルの概要3相ACモーターのスパイスモデルの概要
3相ACモーターのスパイスモデルの概要
 
SPICE Model of TA7291P
SPICE Model of TA7291PSPICE Model of TA7291P
SPICE Model of TA7291P
 
LM555
LM555LM555
LM555
 
Cn3210001005
Cn3210001005Cn3210001005
Cn3210001005
 
Concept Kit:PWM Buck Converter Transients Model
Concept Kit:PWM Buck Converter Transients ModelConcept Kit:PWM Buck Converter Transients Model
Concept Kit:PWM Buck Converter Transients Model
 
DRV401AIDWPG4
DRV401AIDWPG4DRV401AIDWPG4
DRV401AIDWPG4
 
ICE Presentation: Integrated Component Characterization Environment
ICE Presentation: Integrated Component Characterization EnvironmentICE Presentation: Integrated Component Characterization Environment
ICE Presentation: Integrated Component Characterization Environment
 
At24 c512b
At24 c512bAt24 c512b
At24 c512b
 
A3918 low voltage dc motor driver allegro datasheet[1]
A3918 low voltage dc motor driver allegro   datasheet[1]A3918 low voltage dc motor driver allegro   datasheet[1]
A3918 low voltage dc motor driver allegro datasheet[1]
 
Lm741
Lm741Lm741
Lm741
 
Electronic circuit design lab manual
Electronic circuit design lab manualElectronic circuit design lab manual
Electronic circuit design lab manual
 
Objective2
Objective2Objective2
Objective2
 
Objective5
Objective5Objective5
Objective5
 
SPICE MODEL of uPC78L10J in SPICE PARK
SPICE MODEL of uPC78L10J in SPICE PARKSPICE MODEL of uPC78L10J in SPICE PARK
SPICE MODEL of uPC78L10J in SPICE PARK
 
Programming And Controlling Puma Arms
Programming And Controlling Puma ArmsProgramming And Controlling Puma Arms
Programming And Controlling Puma Arms
 
Ec 2-simulation-lab
Ec 2-simulation-labEc 2-simulation-lab
Ec 2-simulation-lab
 
SPICE MODEL of uPC2407A in SPICE PARK
SPICE MODEL of uPC2407A in SPICE PARKSPICE MODEL of uPC2407A in SPICE PARK
SPICE MODEL of uPC2407A in SPICE PARK
 
Objectives
ObjectivesObjectives
Objectives
 
R2 R
R2 RR2 R
R2 R
 
Ec ii lab manual
Ec ii lab manualEc ii lab manual
Ec ii lab manual
 

Destacado

AVR 기초와 응용 강의노트(최한호)
AVR 기초와 응용 강의노트(최한호)AVR 기초와 응용 강의노트(최한호)
AVR 기초와 응용 강의노트(최한호)활 김
 
아두이노와 Fpga를 이용한 로봇제작
아두이노와 Fpga를 이용한 로봇제작아두이노와 Fpga를 이용한 로봇제작
아두이노와 Fpga를 이용한 로봇제작chcbaram
 
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 - Lecture4AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9AL-AWAIL for Electronic Engineering
 
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 - Lecture3AL-AWAIL for Electronic Engineering
 
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 - Lecture11AL-AWAIL for Electronic Engineering
 
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 - Lecture8AL-AWAIL for Electronic Engineering
 
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12AL-AWAIL for Electronic Engineering
 
Robot After 10 Years
Robot After 10 YearsRobot After 10 Years
Robot After 10 YearsSung uk ham
 
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 -Lecture5AL-AWAIL for Electronic Engineering
 
Character smart paper toy robot
Character smart paper toy robotCharacter smart paper toy robot
Character smart paper toy robotDeok Hyeon Ko
 
Open source Embedded systems
Open source Embedded systemsOpen source Embedded systems
Open source Embedded systemsH K Yoon
 
[드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23][드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23]chcbaram
 

Destacado (13)

AVR 기초와 응용 강의노트(최한호)
AVR 기초와 응용 강의노트(최한호)AVR 기초와 응용 강의노트(최한호)
AVR 기초와 응용 강의노트(최한호)
 
아두이노와 Fpga를 이용한 로봇제작
아두이노와 Fpga를 이용한 로봇제작아두이노와 Fpga를 이용한 로봇제작
아두이노와 Fpga를 이용한 로봇제작
 
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 - Lecture9
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture9Embedded 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 - 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 - 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 - 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 - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
Embedded System Microcontroller Interactive Course using BASCOM-AVR - Lecture12
 
Robot After 10 Years
Robot After 10 YearsRobot After 10 Years
Robot After 10 Years
 
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
 
Character smart paper toy robot
Character smart paper toy robotCharacter smart paper toy robot
Character smart paper toy robot
 
Open source Embedded systems
Open source Embedded systemsOpen source Embedded systems
Open source Embedded systems
 
[드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23][드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23]
 

Similar a Programming Microcontrollers Made Easy

Basic engineering electronics Op Amp.pdf
Basic engineering electronics Op Amp.pdfBasic engineering electronics Op Amp.pdf
Basic engineering electronics Op Amp.pdfhappycocoman
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language samt7
 
รายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคมรายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคมChetoss Retos
 
รายงานการทำ Lab วันที่ 10 ธันวาคม .1
รายงานการทำ Lab วันที่ 10 ธันวาคม .1รายงานการทำ Lab วันที่ 10 ธันวาคม .1
รายงานการทำ Lab วันที่ 10 ธันวาคม .1Chetoss Retos
 
รายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคมรายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคมChetoss Retos
 
รายงานการทำ Lab วันที่ 10 ธันวาคม 2
รายงานการทำ Lab วันที่ 10 ธันวาคม 2รายงานการทำ Lab วันที่ 10 ธันวาคม 2
รายงานการทำ Lab วันที่ 10 ธันวาคม 2Chetoss Retos
 

Similar a Programming Microcontrollers Made Easy (7)

Basic engineering electronics Op Amp.pdf
Basic engineering electronics Op Amp.pdfBasic engineering electronics Op Amp.pdf
Basic engineering electronics Op Amp.pdf
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
รายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคมรายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคม
 
รายงานการทำ Lab วันที่ 10 ธันวาคม .1
รายงานการทำ Lab วันที่ 10 ธันวาคม .1รายงานการทำ Lab วันที่ 10 ธันวาคม .1
รายงานการทำ Lab วันที่ 10 ธันวาคม .1
 
รายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคมรายงานการทำ Lab วันที่ 10 ธันวาคม
รายงานการทำ Lab วันที่ 10 ธันวาคม
 
รายงานการทำ Lab วันที่ 10 ธันวาคม 2
รายงานการทำ Lab วันที่ 10 ธันวาคม 2รายงานการทำ Lab วันที่ 10 ธันวาคม 2
รายงานการทำ Lab วันที่ 10 ธันวาคม 2
 
Test Requirements for Microprocessor Relays
Test Requirements for Microprocessor RelaysTest Requirements for Microprocessor Relays
Test Requirements for Microprocessor Relays
 

Último

The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Último (20)

The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Programming Microcontrollers Made Easy

  • 1.    ‫ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ‬     Programming Embedded Systems Microcontroller You Can Practice Microcontroller Programming Easily Now! WALID BALID, Tuesday, December 15, 2009
  • 2.   Essential Instructions in Bascom-AVR Bascom-AVR   ·     $regfile = "m128def.dat"  ATmega128 $crystal = 1000000   $baud = 9600     ·     Wait value  Value Waitms value  Value Waitus value  Value  / ·     Config Portc = Output  C Config Portc.5 = Output C5 Config Portc = Input  C Config Pinc.5 = Input C5 Portc = 255 C Pinc.5 = 1 C5 Pinc.5 = 0 C5 Portc = &B11110000 C / Config Portc = &B11110000  10 Leds Alias Portd  LedsD Leds Alias Portd.5  Led5          42 
  • 3. Practical Class 2 Programming Microcontrollers  Set/Reset ·     Set bit  / Reset bit  / Toggle bit  /     ·     If Expression1 Then Statements1            ... Elseif Expression2 Then   Statements2  11 ... Else 22 Statements3 ...  3 End If SELECT CASE var            Case Test1 : Statements1   Case Test2 : Statements2  1 var = Test1 Case Else : Statements3  2 var = Test2  3 END SELECT   ·     Do          Statements   Loop [until Expression] While Condition Statements    Wend For Var = Start To End [step Value]           Statements End  Start Next Var  .step Exit For For Exit Do Do Exit While  While Faculty of Electrical and Electronic Eng. 43 Automatic Control & Automation Dept.
  • 4.    SRAM ·     Dim Var1 As Bit  0 or 1 Dim Var2 As Byte 0 to 255 Dim Var3 As Integer -32,768 to +32,767 Dim Var4 As Word 0 to 65535 Dim Var5 As Long -2147483648 to 2147483647 Dim Var6 As Single 1.5 x 10^–45 to 3.4 x 10^38 Dim Var7 As Double  Dim Var8 As String * 1  * chr_num Dim Array(8) As Byte   Const Symbol = Numconst Ex. Const Pi = 3.14159265358979   Const Symbol = Stringconst Ex. Const S = "TEST"   Const Symbol = Expression Ex. Const E =(b1 * 3) + 2   Local Var As Type     ·         Px.y      Debounce Px.y , state , label , Sub Ex. Debounce Key1 , 0 , Sw1 , Sub state  label Debounce  Config Debounce = time    Bitwait x , Set/reset           Ex. Bitwait Pinb.7 , reset    44 
  • 5. Practical Class 2 Programming Microcontrollers Exp.1: Scrolling LEDs              JP9, JP10     .LEDs7 -1  -2  -3 Faculty of Electrical and Electronic Eng. 45 Automatic Control & Automation Dept.
  • 6.     -4   $regfile = "m128def.dat" $crystal = 1000000   '----------------------- Config Portd.0 = Output Config Portd.1 = Output Config Portd.2 = Output Config Portd.3 = Output   Config Porte.4 = Output Config Porte.5 = Output Config Porte.6 = Output Config Porte.7 = Output '----------------------- Leds1 Alias Portd  Leds2 Alias Porte  '----------------------- Dim I As Byte , J As Byte   '----------------------- Do For I = 0 To 3 J = I + 4  Set Leds1.i Set Leds2.j   Wait 1 Next I For I = 3 To 0 Step -1 J = I + 4 Reset Leds1.i  Reset Leds2.j Wait 1   Next I Loop End    46 
  • 7. Practical Class 2 Programming Microcontrollers Exp.2: Tact Switches              JP6, JP8   Faculty of Electrical and Electronic Eng. 47 Automatic Control & Automation Dept.
  • 8.       GNDJP6, JP8 -1 VCC JP6, GNDJP8 -2  GNDJP6, JP8 $regfile = "m128def.dat" $crystal = 1000000   $baud = 4800 '----------------------- Config Debounce = 150   Config Pind.0 = Input Config Pind.1 = Input Config Pind.2 = Input Config Pind.3 = Input   Config Pine.4 = Input Config Pine.5 = Input Config Pine.6 = Input Config Pine.7 = Input Portd.0 = 1 : Portd.1 = 1 Portd.2 = 1 : Portd.3 = 1 Porte.4 = 1 : Porte.5 = 1   Porte.6 = 1 : Porte.7 = 1 '----------------------- Key1 Alias Pind.0 Key2 Alias Pind.1 Key3 Alias Pind.2 Key4 Alias Pind.3  Key5 Alias Pine.4   Key6 Alias Pine.5 Key7 Alias Pine.6 Key8 Alias Pine.7 '----------------------- Do Debounce Key1 , 0 , Sw1 , Sub Debounce Key2 , 0 , Sw2 , Sub Debounce Key3 , 0 , Sw3 , Sub Debounce Key4 , 0 , Sw4 , Sub   Debounce Key5 , 0 , Sw5 , Sub Debounce Key6 , 0 , Sw6 , Sub   Debounce Key7 , 0 , Sw7 , Sub Debounce Key8 , 0 , Sw8 , Sub Waitms 200 Loop End '-----------------------  48 
  • 9. Practical Class 2 Programming Microcontrollers Sw1:   Print "Switch(1) is pressed!" Return   '/------------ Sw2:   Print "Switch(2) is pressed!" Return '/------------ Sw3: Print "Switch(3) is pressed!" Return '/------------ Sw4: Print "Switch(4) is pressed!" Return '/------------ Sw5: Print "Switch(5) is pressed!" Return '/------------ Sw6: Print "Switch(6) is pressed!" Return '/------------ Sw7: Print "Switch(7) is pressed!" Return '/------------ Sw8: Print "Switch(8) is pressed!" Return Faculty of Electrical and Electronic Eng. 49 Automatic Control & Automation Dept.
  • 10.    VCC JP8‫ و‬GNDJP6,  PortD  S6     $regfile = "m128def.dat" $crystal = 1000000   $baud = 4800 '----------------------- Config Debounce = 150   Config Pind.0 = Input Config Pind.1 = Input Config Pind.2 = Input Config Pind.3 = Input   Config Pine.4 = Input Config Pine.5 = Input Config Pine.6 = Input Config Pine.7 = Input  50 
  • 11. Practical Class 2 Programming Microcontrollers Portd.0 = 0 : Portd.1 = 0 Portd.2 = 0 : Portd.3 = 0 Portd Porte.4 = 1 : Porte.5 = 1 Porte.6 = 1 : Porte.7 = 1  PortE '----------------------- Key1 Alias Pind.0 Key2 Alias Pind.1 Key3 Alias Pind.2 Key4 Alias Pind.3  Key5 Alias Pine.4 Key6 Alias Pine.5   Key7 Alias Pine.6 Key8 Alias Pine.7 '----------------------- Do Debounce Key1 , 0 , Sw1 , Sub Debounce Key2 , 0 , Sw2 , Sub Debounce Key3 , 0 , Sw3 , Sub Debounce Key4 , 0 , Sw4 , Sub Debounce Key5 , 0 , Sw5 , Sub   Debounce Key6 , 0 , Sw6 , Sub   Debounce Key7 , 0 , Sw7 , Sub Debounce Key8 , 0 , Sw8 , Sub Waitms 200 Loop End '----------------------- Sw1: Print "Switch(1) is pressed!" Return '/------------ Sw2: Print "Switch(2) is pressed!" Return '/------------ Sw3: Print "Switch(3) is pressed!" Return '/------------ Sw4: Print "Switch(4) is pressed!" Return '/------------   Sw5: Print "Switch(5) is pressed!"   Return   '/------------ Sw6: Print "Switch(6) is pressed!" Return '/------------ Sw7: Print "Switch(7) is pressed!" Return '/------------ Sw8: Print "Switch(8) is pressed!" Return Faculty of Electrical and Electronic Eng. 51 Automatic Control & Automation Dept.
  • 12.   Exp.3: Expansion Connectors  /    /–        –JP1~ JP6     S VCC -1  GND -2        52 
  • 13. Practical Class 2 Programming Microcontrollers  :GND  · $regfile = "m128def.dat" $crystal = 1000000   $baud = 4800 '----------------------- Config Porte = Input Config Portb = Input Config Portd = Input   Config Portc = Input Config Porta = Input '----------------------- Porta = 255 Portb = 255 Portc = 255   Portd = 255 Porte = 255 '----------------------- Pa_value Alias Pina Pb_value Alias Pinb  Pc_value Alias Pinc Pd_value Alias Pind   Pe_value Alias Pine '----------------------- Do Print "PA= " ; Pa_value Print "PB= " ; Pb_value Print "PC= " ; Pc_value Print "PD= " ; Pd_value   Print "PE= " ; Pe_value   Print "------------" Wait 1 Loop End '-----------------------   Faculty of Electrical and Electronic Eng. 53 Automatic Control & Automation Dept.
  • 14.    :VCC · $regfile = "m128def.dat" $crystal = 1000000   $baud1 = 4800 '----------------------- Config Porte = Input Config Portb = Input Config Portd = Input   Config Portc = Input Config Porta = Input '----------------------- Porta = 0 Portb = 0 Portc = 0   Portd = 0 Porte = 0 '----------------------- Pa_value Alias Pina Pb_value Alias Pinb  Pc_value Alias Pinc Pd_value Alias Pind   Pe_value Alias Pine '----------------------- Open "com2:" For Binary As #1 Do Print #1 , "PA= " ; Pa_value Print #1 , "PB= " ; Pb_value Print #1 , "PC= " ; Pc_value Print #1 , "PD= " ; Pd_value   Print #1 , "PE= " ; Pe_value Print #1 , "-----------"   Wait 1 Loop Close #1 End '-----------------------  54 
  • 15. Practical Class 2 Programming Microcontrollers Exp.4: Controlling Relay (On/Of) f              JP22~ JP21   Faculty of Electrical and Electronic Eng. 55 Automatic Control & Automation Dept.
  • 16.          Portd.7  Portd.5         K2K1   $regfile = "m128def.dat" $crystal = 1000000   '----------------------- Config Portd.5 = Output   Config Portd.7 = Output '----------------------- Relay1 Alias Portd.5  Relay2 Alias Portd.7   '----------------------- Dim I As Byte   '----------------------- For I = 0 To 9 Set Relay1 Wait 2 Set Relay2 Wait 2   Reset Relay1 Wait 2 Reset Relay2 Next I End '-----------------------  56 