Professional Documents
Culture Documents
ﺍﻟﺘﺠﺎﺭﺏ ﺍﻟﻌﻤﻠﻴﺔ
א א
Programming
Embedded Systems Microcontroller
אא א
א
Wאא
KE7-SegmenntF
Wא
Wאא
א
Wאאא
K0 – 9 א J1
K0 – 999 א J2
K0 – 9999 א J3
،אאאאא
א،
א א
Kא
א
K
אא
אאא
אא
א
אא
א 2
אאא
Pra
actical Class 5
5 Prrogramming M
Microcontrolllers
،E
F
אאא
Kא
KECCF
ECAF
،
אא
K
אאא،
אא
א
א
א
אא א
אאאאא
Wא
אאא،EA,…..,,HF
אB,Cא،אאE1F א
Kא
אאPortCאא
א
WאאPortD
P אאא
Facculty of Electrrical and Electtronic Eng.
3 Automatiic Control & A
Automation Dept.
אא א
א
،E
אא אF אא
Kאאא
PortC אא
א אא
: اﻟﻘﻄﻊ اﻟﱵ ﱔ ﰲ ﺣﺎةل ﲻﲻﻞ7-H
7 6-G 5-F 4--E 3-D 2-C 1-BB 0-A
A.BB.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.BB.D.E.G 1 0 1 0 0 1 0 0 2
A.BB.C.D.G 1 0 1 1 0 0 0 0 3
B
B.C.F.G 1 0 0 1 1 0 0 1 4
A.CC.D.F.G 1 0 0 1 0 0 1 0 5
A.CC.D.E.F.G 1 0 0 0 0 0 1 0 6
A
A.B.C 1 1 1 1 1 0 0 0 7
A.B.CC.D.E.F.G 1 0 0 0 0 0 0 0 8
A.BB.C.D.F.G 1 0 0 1 0 0 0 0 9
אא
א 4
אאא
Pra
actical Class 5
5 Prrogramming M
Microcontrolllers
W
אא
&
&HC0 &
&HF9 &
&HA4 &
&HB0 &H99 &H
H92 &H
H82 &H
HF8 &H880 &H990
א،EאאאF א
א
א
K
אא
א
אא
א،
A.BB.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.BB.D.E.G 0 1 0 1 1 0 1 1 2
A.BB.C.D.G 0 1 0 0 1 1 1 1 3
B
B.C.F.G 0 1 1 0 0 1 1 0 4
A.CC.D.F.G 0 1 1 0 1 1 0 1 5
A.CC.D.E.F.G 0 1 1 1 1 1 0 1 6
A
A.B.C 0 0 0 0 0 1 1 1 7
A.B.CC.D.E.F.G 0 1 1 1 1 1 1 1 8
A.BB.C.D.F.G 0 1 1 0 1 1 1 1 9
W
אא
&
&H3F &
&H06 &H5B &H
H4F &H
H66 &H
H6D &H
H7D &H
H07 &H77F &H66F
א
W
KE2555 DECF&H
HFF אא
Facculty of Electrrical and Electtronic Eng.
5 Automatiic Control & A
Automation Dept.
אא א
א
Wאא
،ELUTT: Look-Up TableF
א
א
Kאאאאאא
אא א
אאEE،F
ata var1 , … , varn
Da
.0 אאא،
lab
bel א Data LU
UT
va
ar = Loo dex , la
okup(Ind abel)
KIn
ndex א
א Data
LUT
Va
ar = Loo
okupstr(Index , Label)
KIndexאlabel
EvalueF EIndexF
א
Va
ar = Look
kdown(value,Label,Entries)
) א labelא Data
KEEn
ntriesFא
EאF
estore Label
Re L א la
abel אא Data
a LU
UT
arWאא
Read Va
א
Data LUT
א א א
ead Var
Re
Re
estore א א
א
KVar
א
אא
א 6
אאא
Practical Class 5 Programming Microcontrollers
WE0-9אFאא
KSW34א4א Wא
$regfile = "m128def.dat"
$crystal = 8000000 Kא
'---------------------
Faculty of Electrical and Electronic Eng.
7 Automatic Control & Automation Dept.
אא א
א
WE0 – 99 א
Fאאא
KSW334 א4,5 א W
א
regfile = "m128def.dat"
$r
crystal = 8000000
$c K
א
---------------------
'-
onfig Por
Co rta = Output
Se
egment Al
lias Porta א
אאא
Po
orta = &H
H81
Kא
onfig Por
Co
Di
rtc.4 = Output
isplay1 Alias
A Portc.4
E&H81Fאאאא
אא
onfig Por
Co rtc.5 = Output
Di
isplay2 Alias
A Portc.5 א
א
א
et Displa
Se ay1 : Set Display2
2 Kאא
---------------------
'-
im I As Byte
Di B , J As Byte Kא
'-
---------------------
א
Do
o
For I = 0 To 9
For J = 0 To 9
S
Segment = Lookup(i , Seg)
R
Reset Display1 : Waitms
W 200
S
Set Display1 W
אא
Segment = Lookup(j , Seg)
S ESegF אED
DataFאאא
R
Reset Display2 : Waitms
W 200
S
Set Display2 K،ELLookupFאא
Nextt J
Next I Kאא
oop
Lo Kא
אא
En
nd KKKאא
'-
---------------------
Se
eg:
ata &H81 , &HF3 , &H49 , &H61 , &H
Da H33 ,
H25 , &H05 , &HF1 , &H01 , &H21
&H
Kא
אא
א 8
אאא
Practical Class 5 Programming Microcontrollers
WE0 – 9999אFאא
$regfile = "m128def.dat"
$crystal = 8000000 Kא
'---------------------
Config Porta = Output
Segment Alias Porta אאאא
Porta = &H81
Kא
Config Portc = &B11110000
Display1 Alias Portc.4 E&H81Fאאאא
Display2 Alias Portc.5
Display3 Alias Portc.6 אא
Display4 Alias Portc.7
אא
Set Display1 : Set Display2
Set Display3 : Set Display4 Kאא
'--------------------- Kא
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
Kא
Faculty of Electrical and Electronic Eng.
9 Automatic Control & Automation Dept.
אא א
א
W
KSW2א
Wאא
אא
K
א
א
א אERTCF א א א
א 32.786
3 KHZZ א
KTOSC
C1,2
אא
א 10
אאא
Practical Class 5 Programming Microcontrollers
Wאא
Kאאאאאאאאא
אא א
Config Clock = Soft | User KE|אFאא
Config Date = Dmy , Separator = Char אאאאאא
Time$ = "hh:mm:ss" Kאאא
Date$ = "mm/dd/yy" Kאאא
Var = Time$ אאא
Var = Date$ אאא
Wאא
$regfile = "m128def.dat"
$crystal = 8000000 Kא
'----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E
= Portc.2 , Rs = Portc.3
Kאאא
Config Lcd = 20 * 4 א
'----------------------
Config Clock = Soft
Config Date = Dmy , Separator = / Kאאאא
Enable Interrupts
א/א/א
Time$ = "16:59:00"
Date$ = "14/04/08"
----------------------
Do אEFאאא
Print Time$
Print Date$ Wאא
Lcd Time$ : Locate 2 , 1 : Lcd Date$ אאאא
Wait 1 אאא
Cls
Loop
Kא
Faculty of Electrical and Electronic Eng.
11 Automatic Control & Automation Dept.
אא א
א
אא
א 12
אאא
Practical Class 5 Programming Microcontrollers
W
KאSW37א
KאאSW2א
Wאא
،
Kאאאא
،א א E0 or 1F א א
Kאאאא
0-255 א א א א א ،8-bit
K 0-5VDCאאאE00000000>>11111111F
VOUT = VREF x VAL / 2N
Digital Input
0 ~ 255
Analog Output
0 ~ 5V
Wא،8-bit
Vstep = VM / 2N = 5 / 255 = 0.019 Volt
אאאאא
Kאאא
Vout = Digval x Vstep
Wא 1000 0001=129א
129 x 0.019 = 2.451V
Faculty of Electrical and Electronic Eng.
13 Automatic Control & Automation Dept.
אא א
א
א
א
Wא
א
EV2Fא אאEV1F א א
אאאא
K
א
אאאאא
אא א אא Eא F
K
א
א א
J1
א ، א
،E0-to--VccF
א
K4.5V
Vא EVcc - 0.5VVF
אא J2
،
א
KE3.9V אF
אאא
אא
א
א
K5V
V6..5V
D7
D א
אא
K 0 to 2.5V א
אא
א 14
אאא
Practical Class 5 Programming Microcontrollers
5.5V ~ 12V
Wאא
Kאאאא
אא א
WKExFא
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 KאאאExF
Var=-1 x<0אKExFא
Var = Sgn(x)
Var=1 x>0א
Wאא
$regfile = "m128def.dat"
$crystal = 8000000 Kא
'-----------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 =
Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E
= Portc.2 , Rs = Portc.3
Kאאא
Config Lcd = 20 * 4 א
'----------------------
Config Porte = Output
Digital Alias Porte
'-----------------------
Kאאא
Dim I As Byte , V_out As Single
Const Vlot_step = 5 / 255
'----------------------- Kאאא
Cls
Do
For I = 0 To 255
Digital = I Wאא
V_out = I * Vlot_step
Lcd "DAC OUT= " ; V_out EFאא
Wait 1 : Cls
Next I
Kאא
Loop אא
End
Kאא
Faculty of Electrical and Electronic Eng.
15 Automatic Control & Automation Dept.
אא א
א
W
KSW2א
KאאJP11, JP122EJumperssFא
Wאא
K
א א
אא
א 16
אאא
Practical Class 5 Programming Microcontrollers
אאEאאF ANI0אאאא
א،HighאאE אאF AIN1א
KLowאאAIN0אאאANI1א
אאאאאאאאא
Kא
אא 1א/אא
Kאאאאאא
Wאא
Kאאאאאאאאא
אא א
אא | WEAci=On|offF
Kא
1א ?? WECompare=On|offF
Kאאא
WאWETriggerF
Config Aci= On|off , (Ain0 > Ain1) :Rising
Compare= On|off ,
Trigger = TOGGLE|RISING|FALLING אא?Ain0?אא
K?Ain1?
(Ain0 < Ain1) :Falling
אא?Ain0?אא
K?Ain1?
(Ain0 > Ain1 and Ain0 < Ain1) :Toggle
Enable Aci Kאא
א א
On Aci label
K?label?אאא
Start Ac Kאא
Stop Ac Kאאא
אא א א א
Enable Interrupts
Kא
?Assembly?אא
nop
Kאא
Faculty of Electrical and Electronic Eng.
17 Automatic Control & Automation Dept.
אא א
א
Wאאא
regfile = "m128def.dat"
$r
crystal = 8000000
$c K
א
-----------------------
'-
onfig Lcd
Co dpin = Pin , Db4 = Portc.4
4 , Db5 =
ortc.5 , Db6 = Portc.6 , Db7
Po
E = Portc.2 , Rs = Portc.3
D = Por
rtc.7 , Kאאא
d = 20 * 4
onfig Lcd
Co א
onfig Aci
Co i = On , Compare = Off , Trigger
T =
Ri
ising א
אאא
n Aci Isr
On r aci
nable Aci
En i K
tart Ac
St
En
nable Int
terrupts א
א
-----------------------
'-
im I As Byte
Di B
Kא
-----------------------
'- אא
Cl
ls
Do
o
nop
אא
Lo
oop
En
nd K
'-
-----------------------
sr aci:
Is
Cls
I = I + 1 א
א
Lcd "ch
hange: " ; I
Waitms 100
אא
Re
eturn
א
אא
א 18
אאא