SlideShare a Scribd company logo
1 of 18
Download to read offline


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

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

                  

                          




                          




                   Programming
      Embedded Systems Microcontroller

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

      Exp.14: 7-Segment Single Display                     


                                                                                             
                                                                 7-Segment
                                                                                              




 
                                                                                              
                                      
                                                           0 – 9 1
                                                          0 – 99 2
                                                       0 – 9999 3
      
      
                                                                                               
                                             
                              92                       
Practical Class 5                                                                          Programming Microcontrollers




  
                                                                              
   CCCA
                           
  
          A,…..,H




                                                
                                                                                                                            
  B,C1
                                                                                                             




 
                                                                                                                            
  PortC
                                                       PortD
      Faculty of Electrical and Electronic Eng.                         93                 Automatic Control & Automation Dept.
                                                                     




      

                                                               
                                            PortC                  
               :‫-7 اﻟﻘﻄﻊ اﻟﱵ ﱔ ﰲ ﺎ ﲻﻞ‬H 6-G 5-F 4-E 3-D 2-C 1-B 0-A                     

          A.B.C.D.E.F             1    1     0        0   0      0     0       0                      0
              B.C                 1    1     1        1   1      0     0        1                     1
           A.B.D.E.G              1    0     1        0   0      1     0       0                      2
           A.B.C.D.G              1    0     1        1   0      0     0       0                      3
            B.C.F.G               1    0     0        1   1      0     0        1                     4
           A.C.D.F.G              1    0     0        1   0      0     1       0                      5
          A.C.D.E.F.G             1    0     0        0   0      0     1       0                      6
             A.B.C                1    1     1        1   1      0     0       0                      7
         A.B.C.D.E.F.G            1    0     0        0   0      0     0       0                      8
          A.B.C.D.F.G             1    0     0        1   0      0     0       0                      9
                     94                    
Practical Class 5                                                                           Programming Microcontrollers

                                          




 
       &HC0              &HF9      &HA4           &HB0       &H99        &H92        &H82        &HF8        &H80       &H90


  
                             

                      :‫اﻟﻘﻄﻊ اﻟﱵ ﱔ ﰲ ﺎ ﲻﻞ‬                    PortC                        
                                                   7-H 6-G 5-F 4-E 3-D 2-C 1-B 0-A                                

                 A.B.C.D.E.F                        0    0          1        1   1      1         1      1                     0
                     B.C                            0    0          0        0   0      1         1      0                     1
                  A.B.D.E.G                         0    1          0        1   1      0         1      1                     2
                  A.B.C.D.G                         0    1          0        0   1      1         1      1                     3
                   B.C.F.G                          0    1          1        0   0      1         1      0                     4
                  A.C.D.F.G                         0    1          1        0   1      1         0      1                     5
                 A.C.D.E.F.G                        0    1          1        1   1      1         0      1                     6
                    A.B.C                           0    0          0        0   0      1         1      1                     7
                A.B.C.D.E.F.G                       0    1          1        1   1      1         1      1                     8
                 A.B.C.D.F.G                        0    1          1        0   1      1         1      1                     9
                                                                                                                              
                                          




 
       &H3F              &H06     &H5B            &H4F   &H66            &H6D        &H7D        &H07        &H7F       &H6F


      
                                                                     255 DEC&HFF

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

                                                                                            
 LUT: Look-Up Table            
                                
                                                            
                                                         
Data var1 , … , varn
                                                                           .0
                                                         label Data LUT
var = Lookup(Index , label)
                                                                                             Index
                                                           Data   LUT   
Var = Lookupstr(Index , Label)
                                                                                   Indexlabel
                                                           value  Index   
Var = Lookdown(value,Label,Entries)                       label Data
                                                                                Entries
                                                                 
Restore Label                                             label Data LUT
                                                                           Read Var
                                                           Data   LUT     
Read Var                                                   Restore    
                                                                                                   Var
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                                                                                                                 
                            96                         
Practical Class 5                                                                Programming Microcontrollers

                                                0-9
                                             SW344 
$regfile = "m128def.dat"
$crystal = 8000000                                                             
'---------------------
                                                                 
Config Porta = Output
Segment Alias Porta                                           &H81
Porta = &H81                                                          
Config Portc.4 = Output                                                             
Ctr1 Alias Portc.4
Reset Ctr1                                                   
'---------------------
Dim I As Byte                                                                
'---------------------
Do
   For I = 0 To 9
      Segment = Lookup(i , Seg)                                       
      Waitms 1000
   Next I
                                                                SegData
Loop                                                           Lookup
End
'---------------------

Seg:                                                                    
Data &H81 , &HF3 , &H49 , &H61 , &H33 ,
&H25 , &H05 , &HF1 , &H01 , &H21




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

                                0 – 99
                                    SW344,5 
$regfile = "m128def.dat"
$crystal = 8000000                                                       
'---------------------
Config Porta = Output                                   
Segment Alias Porta
Porta = &H81                                                               
Config Portc.4 = Output                                 &H81
Display1 Alias Portc.4                                          
Config Portc.5 = Output                                 
Display2 Alias Portc.5
                                                                        
Set Display1 : Set Display2                                       
'---------------------
Dim I As Byte , J As Byte                                              
'---------------------

Do
     For I = 0 To 9
        For J = 0 To 9                                          
           Segment = Lookup(i , Seg)
           Reset Display1 : Waitms 20                     SegData
           Set Display1
                                                         Lookup
         Segment = Lookup(j , Seg)                                
         Reset Display2 : Waitms 20
         Set Display2                                      
      Next J
   Next I
                                                                       
Loop

End
'---------------------
Seg:
Data &H81 , &HF3 , &H49 , &H61 , &H33 ,                           
&H25 , &H05 , &HF1 , &H01 , &H21




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

                                      0 – 9999
$regfile = "m128def.dat"
$crystal = 8000000                                                                
'---------------------
Config Porta = Output
Segment Alias Porta                                              
Porta = &H81
                                                                                   
Config Portc =          &B11110000                              &H81
Display1 Alias          Portc.4
Display2 Alias          Portc.5                                          
Display3 Alias          Portc.6                                   
Display4 Alias          Portc.7
                                                                                
Set Display1 : Set Display2
Set Display3 : Set Display4
                                                                           
'---------------------
Dim I As Byte , J As Byte
Dim K As Byte , L As Byte                                                      
'---------------------
Do
   For I = 0 To 9
      For J = 0 To 9
         For K = 0 To 9
            For L = 0 To 9
               Segment = Lookup(i , Seg)
               Reset Display1 : Waitms 7
               Set Display1
                                                                        
                        Segment = Lookup(j , Seg)
                        Reset Display2 : Waitms 7                 SegData
                        Set Display2                              Lookup
                        Segment = Lookup(k , Seg)                          
                        Reset Display3 : Waitms 7
                        Set Display3                                
                                                                                  
                Segment = Lookup(l , Seg)
                Reset Display4 : Waitms 7                                      
                Set Display4
             Next L
         Next K
      Next J
   Next I
Loop

End
'---------------------
Seg:
Data &H81 , &HF3 , &H49 , &H61 , &H33 ,                                   
&H25 , &H05 , &HF1 , &H01 , &H21

                                                                                                                 

                                                                                                                 

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

      Exp.15: Real Time Clock                              

                                                                                           
                                                          
                                                                                            




 
                                                                                             
                                                                                      SW2
                                                                                                                 
                                                                                              
                                     
                                                                              
                                       RTC         
                                       32.786 KHZ       
                                                                                                     TOSC1,2

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

                                                                                             
                            
                                                           
Config Clock = Soft | User                                        |
Config Date = Dmy , Separator = Char                   
Time$ = "hh:mm:ss"                                                  
Date$ = "mm/dd/yy"                                                    
Var = Time$                                                                             
Var = Date$                                                                            


                                                                                         
$regfile = "m128def.dat"
$crystal = 8000000                                                                 Directives
'----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E
= Portc.2 , Rs = Portc.3                                                 Configure the LCD display
Config Lcd = 20 * 4
'----------------------
Config Clock = Soft                                             
Config Date = Dmy , Separator = /
Enable Interrupts                                                    //
                                                                                       
Time$ = "16:59:00"
Date$ = "14/04/08"                                              
----------------------
Do
   Print Time$                                                          
   Print Date$
                                                              
    Lcd Time$ : Locate 2 , 1 : Lcd Date$
                                                                    
   Wait 1                                                                       
   Cls
Loop




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

      Exp.16: DAC using Ladder R-2R                 

                                                                                
                                       R-2R
                                                                                 




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

                                                                                              
                                                 SW37
                                                        SW2
                                                                                               
 
                                              
      0 or 1         
                      
0-255         8-bit       
                                0-5VDC00000000>>11111111
                                                V OUT = V REF x VAL / 2N
 Digital Input
   0 ~ 255




                                                                                                  Analog Output
                                                                                                     0 ~ 5V



             
                                                                                                                
                   ،8-bit
                                         Vstep = VM / 2N = 5 / 255 = 0.019 Volt

                                                                                        
                                                   Vout = Digval x V step
         1000 0001=129
                                                  129 x 0.019 = 2.451V
 Faculty of Electrical and Electronic Eng.                    103              Automatic Control & Automation Dept.
                                                                 

   
                                                                                      




 
                                                                                                       
  V2V1
  
                                             
                                                                                              
                                               1
                                             
                                     0-to-Vcc      
                                      4.5VVcc - 0.5V
                                       2
                                            
                                           3.9V
                                      
                                                                                   5V6.5V
                                     D7
                                                          0 to 2.5V 

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




                                                                    5.5V ~ 12V




                     
                                                                                        
           
                                                         
                                                             x
Var = Round(x)                                                Round(2.3) = 2 , Round(2.8) = 3
                                                        Round(-2.3)   = -2 , Round(-2.8) = -3
Var = Int(source)              Ex: Int(134.567)=134                          
Var = Frac(source) Ex: Frac(134.567)=567                                   
Var = Fix(x)                   EX: Fix(12.98)=12             x
                                                             Var=-1  x<0x
Var = Sgn(x)
                                                                                     Var=1  x>0


                                                                                      
$regfile = "m128def.dat"
$crystal = 8000000                                               
'-----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E  
= Portc.2 , Rs = Portc.3
Config Lcd = 20 * 4
                                                         
'----------------------
Config Porte = Output                              
Digital Alias Porte
'-----------------------                                              
Dim I As Byte , V_out As Single
Const Vlot_step = 5 / 255                                
'-----------------------
Cls
Do
                                                      
   For I = 0 To 255
      Digital = I                             
      V_out = I * Vlot_step
      Lcd "DAC OUT= " ; V_out                 
      Wait 1 : Cls                           
   Next I
Loop                                                       
End

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

      Exp.17: Analog Comparator                                         

                                                                                            
                                      
                                                                                             




 
                                                                                              
                                                                                      SW2
                           JP11, JP12Jumpers
                                                                                               
           


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

 ANI0
High   AIN1
         LowAIN0ANI1
 
                                                                                            
  1/
            
                                                                                                                  
                                                                                           
                            
                                                            
                                                           | Aci=On|off
                                                                                                      
                                                         1     Compare=On|off
                                                                         
                                                      Trigger
Config Aci= On|off ,
Compare= On|off ,                                         (Ain0 > Ain1) :Rising
Trigger = TOGGLE|RISING|FALLING                        Ain0
                                                                                                    Ain1
                                                              (Ain0 < Ain1) :Falling
                                                        Ain0
                                                                                                     Ain1
                                                       (Ain0 > Ain1 and Ain0 < Ain1) :Toggle
Enable Aci                                                                
                                                               
On Aci label
                                                                            label
Start Ac                                                                          
Stop Ac                                                                  
                                                                
Enable Interrupts
                                                                                      
                                                       Assembly
nop
                                                                                       



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

                                                                           
$regfile = "m128def.dat"
$crystal = 8000000                                           
'-----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 ,    
E = Portc.2 , Rs = Portc.3
Config Lcd = 20 * 4
                                                      

Config Aci = On , Compare = Off , Trigger =         
Rising
On Aci Isr_aci                                                     
Enable Aci                                          
Start Ac
Enable Interrupts                                                    
'-----------------------                                       
Dim I As Byte
'-----------------------
Cls                                                   
Do
   nop                                                        
Loop                                                                     
End
'-----------------------

Isr_aci:                                                
   Cls
   I = I + 1                                        
   Lcd "change: " ; I                                                 
   Waitms 100
Return
                                           

                                           




                                




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

More Related Content

Viewers also liked

Control in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation SystemsControl in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation SystemsKamel Alhomsi
 
Mechatronics Programs
Mechatronics  ProgramsMechatronics  Programs
Mechatronics ProgramsEmad Ezzat
 
Decision support systems (ch4)
Decision support systems (ch4)Decision support systems (ch4)
Decision support systems (ch4)DrSamahAhmed
 
Decision support systems (ch1)
Decision support systems (ch1)Decision support systems (ch1)
Decision support systems (ch1)DrSamahAhmed
 
شرح Protecting stp topology
شرح Protecting stp topologyشرح Protecting stp topology
شرح Protecting stp topologyAli Elsayed Saleh
 
شهادة ال CCNP
شهادة ال CCNPشهادة ال CCNP
شهادة ال CCNPrayan7312
 
Cisco certs guide - iTawy
Cisco certs guide - iTawyCisco certs guide - iTawy
Cisco certs guide - iTawyiTawy Community
 
Nature of Electricity
Nature of Electricity Nature of Electricity
Nature of Electricity Aalwan Aziz
 
GIS: Geographic Information Systems
GIS: Geographic Information SystemsGIS: Geographic Information Systems
GIS: Geographic Information Systemsaalaa gaffar
 
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 - 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 - Lecture6AL-AWAIL for Electronic Engineering
 
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 -Lecture7AL-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
 

Viewers also liked (20)

Control in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation SystemsControl in Electric Vechicle Transportation Systems
Control in Electric Vechicle Transportation Systems
 
Mechatronics Programs
Mechatronics  ProgramsMechatronics  Programs
Mechatronics Programs
 
Decision support systems (ch4)
Decision support systems (ch4)Decision support systems (ch4)
Decision support systems (ch4)
 
Decision support systems (ch1)
Decision support systems (ch1)Decision support systems (ch1)
Decision support systems (ch1)
 
شرح Protecting stp topology
شرح Protecting stp topologyشرح Protecting stp topology
شرح Protecting stp topology
 
Ccnp m
Ccnp mCcnp m
Ccnp m
 
شهادة ال CCNP
شهادة ال CCNPشهادة ال CCNP
شهادة ال CCNP
 
1
11
1
 
Aaa security
Aaa securityAaa security
Aaa security
 
Cisco certs guide - iTawy
Cisco certs guide - iTawyCisco certs guide - iTawy
Cisco certs guide - iTawy
 
Nature of Electricity
Nature of Electricity Nature of Electricity
Nature of Electricity
 
جودة القدرة Power quality
جودة القدرة Power qualityجودة القدرة Power quality
جودة القدرة Power quality
 
GIS: Geographic Information Systems
GIS: Geographic Information SystemsGIS: Geographic Information Systems
GIS: Geographic Information Systems
 
AVR PPT
AVR PPTAVR PPT
AVR PPT
 
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 - 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 -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 - 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
 

Similar to Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5

Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronicsIIT, KANPUR INDIA
 
Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronicsKamil Hussain
 
343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011e11ie
 
Senior Project Presentation
Senior Project PresentationSenior Project Presentation
Senior Project PresentationTim Heath
 
Assessment questions probability
Assessment questions  probabilityAssessment questions  probability
Assessment questions probabilityErik Tjersland
 
Pma individual assignment ii
Pma  individual assignment iiPma  individual assignment ii
Pma individual assignment iichandraswami
 
86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuits86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuitsLekashri Subramanian
 

Similar to Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5 (8)

Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronics
 
Decoder for digital electronics
Decoder for digital electronicsDecoder for digital electronics
Decoder for digital electronics
 
343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011343logic-design-lab-manual-10 esl38-3rd-sem-2011
343logic-design-lab-manual-10 esl38-3rd-sem-2011
 
Senior Project Presentation
Senior Project PresentationSenior Project Presentation
Senior Project Presentation
 
Assessment questions probability
Assessment questions  probabilityAssessment questions  probability
Assessment questions probability
 
00857a
00857a00857a
00857a
 
Pma individual assignment ii
Pma  individual assignment iiPma  individual assignment ii
Pma individual assignment ii
 
86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuits86254 162058-ee2255-digital-logic-circuits
86254 162058-ee2255-digital-logic-circuits
 

Recently uploaded

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
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

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
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
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"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Embedded System Microcontroller Interactive Course using BASCOM-AVR -Lecture5

  • 1.    ‫ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ‬     Programming Embedded Systems Microcontroller You Can Practice Microcontroller Programming Easily Now! WALID BALID, Tuesday, December 15, 2009
  • 2.     Exp.14: 7-Segment Single Display       7-Segment         0 – 9 1 0 – 99 2 0 – 9999 3        92 
  • 3. Practical Class 5 Programming Microcontrollers     CCCA     A,…..,H      B,C1       PortC  PortD Faculty of Electrical and Electronic Eng. 93 Automatic Control & Automation Dept.
  • 4.          PortC    :‫-7 اﻟﻘﻄﻊ اﻟﱵ ﱔ ﰲ ﺎ ﲻﻞ‬H 6-G 5-F 4-E 3-D 2-C 1-B 0-A    A.B.C.D.E.F 1 1 0 0 0 0 0 0 0 B.C 1 1 1 1 1 0 0 1 1 A.B.D.E.G 1 0 1 0 0 1 0 0 2 A.B.C.D.G 1 0 1 1 0 0 0 0 3 B.C.F.G 1 0 0 1 1 0 0 1 4 A.C.D.F.G 1 0 0 1 0 0 1 0 5 A.C.D.E.F.G 1 0 0 0 0 0 1 0 6 A.B.C 1 1 1 1 1 0 0 0 7 A.B.C.D.E.F.G 1 0 0 0 0 0 0 0 8 A.B.C.D.F.G 1 0 0 1 0 0 0 0 9  94 
  • 5. Practical Class 5 Programming Microcontrollers     &HC0 &HF9 &HA4 &HB0 &H99 &H92 &H82 &HF8 &H80 &H90      :‫اﻟﻘﻄﻊ اﻟﱵ ﱔ ﰲ ﺎ ﲻﻞ‬ PortC  7-H 6-G 5-F 4-E 3-D 2-C 1-B 0-A    A.B.C.D.E.F 0 0 1 1 1 1 1 1 0 B.C 0 0 0 0 0 1 1 0 1 A.B.D.E.G 0 1 0 1 1 0 1 1 2 A.B.C.D.G 0 1 0 0 1 1 1 1 3 B.C.F.G 0 1 1 0 0 1 1 0 4 A.C.D.F.G 0 1 1 0 1 1 0 1 5 A.C.D.E.F.G 0 1 1 1 1 1 0 1 6 A.B.C 0 0 0 0 0 1 1 1 7 A.B.C.D.E.F.G 0 1 1 1 1 1 1 1 8 A.B.C.D.F.G 0 1 1 0 1 1 1 1 9       &H3F &H06 &H5B &H4F &H66 &H6D &H7D &H07 &H7F &H6F   255 DEC&HFF Faculty of Electrical and Electronic Eng. 95 Automatic Control & Automation Dept.
  • 6.        LUT: Look-Up Table                      Data var1 , … , varn  .0 label Data LUT var = Lookup(Index , label)  Index   Data   LUT    Var = Lookupstr(Index , Label)  Indexlabel   value  Index    Var = Lookdown(value,Label,Entries)  label Data  Entries           Restore Label  label Data LUT Read Var   Data   LUT      Read Var   Restore      Var                          96 
  • 7. Practical Class 5 Programming Microcontrollers  0-9  SW344  $regfile = "m128def.dat" $crystal = 8000000   '---------------------   Config Porta = Output Segment Alias Porta &H81 Porta = &H81   Config Portc.4 = Output   Ctr1 Alias Portc.4 Reset Ctr1   '--------------------- Dim I As Byte   '--------------------- Do For I = 0 To 9 Segment = Lookup(i , Seg)   Waitms 1000 Next I SegData Loop  Lookup End '--------------------- Seg:   Data &H81 , &HF3 , &H49 , &H61 , &H33 , &H25 , &H05 , &HF1 , &H01 , &H21 Faculty of Electrical and Electronic Eng. 97 Automatic Control & Automation Dept.
  • 8.      0 – 99  SW344,5  $regfile = "m128def.dat" $crystal = 8000000   '--------------------- Config Porta = Output  Segment Alias Porta Porta = &H81   Config Portc.4 = Output &H81 Display1 Alias Portc.4   Config Portc.5 = Output  Display2 Alias Portc.5   Set Display1 : Set Display2   '--------------------- Dim I As Byte , J As Byte   '--------------------- Do For I = 0 To 9 For J = 0 To 9   Segment = Lookup(i , Seg) Reset Display1 : Waitms 20 SegData Set Display1  Lookup Segment = Lookup(j , Seg)   Reset Display2 : Waitms 20 Set Display2   Next J Next I   Loop End '--------------------- Seg: Data &H81 , &HF3 , &H49 , &H61 , &H33 ,   &H25 , &H05 , &HF1 , &H01 , &H21  98 
  • 9. Practical Class 5 Programming Microcontrollers  0 – 9999 $regfile = "m128def.dat" $crystal = 8000000   '--------------------- Config Porta = Output Segment Alias Porta  Porta = &H81   Config Portc = &B11110000 &H81 Display1 Alias Portc.4 Display2 Alias Portc.5   Display3 Alias Portc.6  Display4 Alias Portc.7   Set Display1 : Set Display2 Set Display3 : Set Display4   '--------------------- Dim I As Byte , J As Byte Dim K As Byte , L As Byte   '--------------------- Do For I = 0 To 9 For J = 0 To 9 For K = 0 To 9 For L = 0 To 9 Segment = Lookup(i , Seg) Reset Display1 : Waitms 7 Set Display1   Segment = Lookup(j , Seg) Reset Display2 : Waitms 7 SegData Set Display2  Lookup Segment = Lookup(k , Seg)   Reset Display3 : Waitms 7 Set Display3     Segment = Lookup(l , Seg) Reset Display4 : Waitms 7   Set Display4 Next L Next K Next J Next I Loop End '--------------------- Seg: Data &H81 , &HF3 , &H49 , &H61 , &H33 ,   &H25 , &H05 , &HF1 , &H01 , &H21   Faculty of Electrical and Electronic Eng. 99 Automatic Control & Automation Dept.
  • 10.     Exp.15: Real Time Clock              SW2          RTC            32.786 KHZ         TOSC1,2  100 
  • 11. Practical Class 5 Programming Microcontrollers           Config Clock = Soft | User  | Config Date = Dmy , Separator = Char   Time$ = "hh:mm:ss"   Date$ = "mm/dd/yy"   Var = Time$   Var = Date$     $regfile = "m128def.dat" $crystal = 8000000 Directives '---------------------- Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.3  Configure the LCD display Config Lcd = 20 * 4 '---------------------- Config Clock = Soft   Config Date = Dmy , Separator = / Enable Interrupts  //   Time$ = "16:59:00" Date$ = "14/04/08"   ---------------------- Do Print Time$   Print Date$   Lcd Time$ : Locate 2 , 1 : Lcd Date$  Wait 1   Cls Loop Faculty of Electrical and Electronic Eng. 101 Automatic Control & Automation Dept.
  • 12.     Exp.16: DAC using Ladder R-2R      R-2R      102 
  • 13. Practical Class 5 Programming Microcontrollers    SW37 SW2             0 or 1            0-255         8-bit         0-5VDC00000000>>11111111 V OUT = V REF x VAL / 2N Digital Input 0 ~ 255 Analog Output 0 ~ 5V      ،8-bit Vstep = VM / 2N = 5 / 255 = 0.019 Volt    Vout = Digval x V step   1000 0001=129 129 x 0.019 = 2.451V Faculty of Electrical and Electronic Eng. 103 Automatic Control & Automation Dept.
  • 14.             V2V1                       1          0-to-Vcc        4.5VVcc - 0.5V   2         3.9V    5V6.5V D7   0 to 2.5V   104 
  • 15. Practical Class 5 Programming Microcontrollers 5.5V ~ 12V              x Var = Round(x) Round(2.3) = 2 , Round(2.8) = 3  Round(-2.3) = -2 , Round(-2.8) = -3 Var = Int(source) Ex: Int(134.567)=134   Var = Frac(source) Ex: Frac(134.567)=567   Var = Fix(x) EX: Fix(12.98)=12  x Var=-1  x<0x Var = Sgn(x) Var=1  x>0   $regfile = "m128def.dat" $crystal = 8000000   '----------------------- Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E   = Portc.2 , Rs = Portc.3 Config Lcd = 20 * 4   '---------------------- Config Porte = Output   Digital Alias Porte '-----------------------   Dim I As Byte , V_out As Single Const Vlot_step = 5 / 255   '----------------------- Cls Do   For I = 0 To 255 Digital = I  V_out = I * Vlot_step Lcd "DAC OUT= " ; V_out   Wait 1 : Cls  Next I Loop   End Faculty of Electrical and Electronic Eng. 105 Automatic Control & Automation Dept.
  • 16.     Exp.17: Analog Comparator              SW2  JP11, JP12Jumpers      106 
  • 17. Practical Class 5 Programming Microcontrollers  ANI0 High   AIN1  LowAIN0ANI1       1/                   | Aci=On|off     1     Compare=On|off    Trigger Config Aci= On|off , Compare= On|off ,    (Ain0 > Ain1) :Rising Trigger = TOGGLE|RISING|FALLING Ain0 Ain1  (Ain0 < Ain1) :Falling Ain0 Ain1  (Ain0 > Ain1 and Ain0 < Ain1) :Toggle Enable Aci            On Aci label  label Start Ac   Stop Ac             Enable Interrupts   Assembly nop   Faculty of Electrical and Electronic Eng. 107 Automatic Control & Automation Dept.
  • 18.       $regfile = "m128def.dat" $crystal = 8000000   '----------------------- Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 ,   E = Portc.2 , Rs = Portc.3 Config Lcd = 20 * 4   Config Aci = On , Compare = Off , Trigger =  Rising On Aci Isr_aci   Enable Aci  Start Ac Enable Interrupts   '-----------------------   Dim I As Byte '----------------------- Cls  Do nop   Loop   End '----------------------- Isr_aci:   Cls I = I + 1  Lcd "change: " ; I   Waitms 100 Return        108 