ATmtqa 32 progtam
Tt ` a l6 bit datatype that, usts fe MIR
Ploqtammng
Embde C bitdito. kepae Seyttre-Ye aluc
Shancd intie Aanqy from -32 168 to
+ V8&76
Btt Cs Gagle bit)
il S-bit keywo2d is sed to access Eit
add eessable aesIGtoa1 t alloos accels to
So Chaaríeu clata tpe mostly ustd in Sngle bit af the sFR ResretoR
ATneqa 3 fi)Dts Size af 6it i.t erttiee o or 1
Sigacdcholacte SERSpec+al functton Res ittor|
i) the Siqned chauacte u a g-bit claalype
that ws és the MSB Srt Le DT to i)Size datatype is ued to access tnt bit
CFR of
Qepaesent the tve or -ve pth Nalue SER 2eeistDA
sed. to Qepsecent 11> Cts Size s g bit
the m aqhiude address Starts from 80 to FFFH
Ct) Sraned characta Sanges from-l28 to tag
Unsigned atcqer Data Bifes Bytes Ipata Range
ty pes
)The unsiqned int L6 6Tt data type
that ancs frDm 65,535 Uhstgned char to 55
T assaned integer is wed to define a l6 Git Sqned chan -l2e to lQ
Vautable Sucy as. Memoey addies. ¡t is srqhcd iut to 65535
also uSed to Bet Counte vaues Df moae Tut 6 -32, 168 to 3 6 4
than ds6. Bit
3bit Contlo ll ce Sbit to /
the nt datatpe tahes d Gitts of RAm. SFR O to 55
&tSult iw a lasge Hex fle
Conteoller
moto la fn a CNC maichine setup. the System sthould Gnly
Oyous de s+quing a stepper te stepper motn opuote wohts botth Safet dose(eft Rigst)
Pos cNeMitutantt
machit
D4Öpuby clostd. tach dooe it (oniectd to
SPPSa Sequehce it couteotle d by bitt disital twput ou PAO PA 1, ouly whtu
clp JpaHelo. Theee pattin musE be Stnt Hiqh doog close, thc machnc is
Cnce tin a Cequtnce from oX D0 to OKEFH allowcd to 2n
2unl Siqnal scat to poat C)
to test all þosCTble tep CombihatrDh p
Ensure pIDpr motoe driver LeponSe.
ngte a C proqtam fora atmeqa m1erpcont # hclude <utilldlay oin
- (le to Sent e8 bit step Valvee to
port B 36Pts portA’i|p
Pinclude< a v2/io.h> DDRA =oX0D tctt as
#lnclucle < uil de lay. h pott
int mati void ) Post t = Dx00 ’ îuitiate to o post(elp
DDRC= 0XFFtcts. as olp port
DXDO’ Ilp port
poit DDRBoxF.; Poatc
FFofp port fo (s=o; i<=OXFF ;j itt
port B=i; DKo3)
it (ph Oxo3)==
dclay (loop);
po&t c = Oxol ;
=25
(Uint l6-t) í=0, i<fav; tt) elsee
PDrt B= uint |6-t);
delay iool;
în a eith er Ct
d fallt Sens ors (Connect it to PA 2 PA 3)
Can taigqu a fault alaanm. Colp on PB o
f anyone of the seusog i r'ett, tte
elaam Shod acti vafe
8)
a) Watle an Ttga. E program to qet a bile
pott D) feedbnck from SensoRs fa (Via post 4) Sm of dala fronm POxt B, chen Stud it to
tei euU eut stak alhci port c.
Gdicatee
On but. feeclbacki s off or rrce- Versathes # [ncluct.< aa /io.h
it (adicafe a nisiateh erfault. tt Imeude < util /Alay.h7
Systtm houldfalse int maiul vord) U
dusplay the satus on poxt 3
diplay
port A Dlp coniralFeelbath,flag DDRB = DXO0 tcts as 1lp pot
Valut
Port DJ pot B= oxp;’ Byte Valuc
port8 ’ olp D. DPRC = oxFFi’ op port
Wucle Ci).
# aclude < aveo.b> teup =port B;
+ ocluele < utl| delay. h Poztc=tenp ;
int main (vot).
3
DD RA=0XoD ’ Autt as Dlp por t
Post = 0XDD’ Tuitiae to o i k Waite an Atmeqa
Emeqa 32 CCProqram to qet a
DPRD = DxDD ’ tets as D/p pot
D= oXDD Tintate tó o
byte of date fom por te PEus? than
LOo, Send it to poxt B. othuwise Stnd itto
poat
Pott D.
DDR = OxFf ’ tet as ’ # (hcule <arelio. h
OxDo
iut man (vod)
Wile () Uniigned (ut tleaq’ oxFrfovoo
DDRY o3 B(nari
Post B Poat h ^ Port D. Poat C l28 DEMmal of25
DDRB= 0xFF3
DDRD0XFFa
te nup potc post D =teiupi
tenp
if (Eenp <loo)
Pot B= tenpi
Clse
Ho mOuiton
Ttga C giucl sH
n |D1D,|
fo. postB.cte)se Send AH to poRt D TNTO D|DGDS|D3
D6 D2
3- pouti focoWl GM Com COM
DI
Port C’ |p
Port B ’olp ’ oxFF;
Port D clp Tnta
wicto CDuttoller, thus, TCNTO as chown
Pro f above
Fnclude <avao.hz TCCRO CTiaecoute Coutiolt acqite)
Resste TCCR îs an g 6it seitfu usea
forl couttol of The bit ef
PUe DDRC0xo ehown in above.
Port C Oxoo5
DDRB =0X FP CO CsooTimer 2ero el
PertgE
bBRD =0xFF5 These bits h the TccRO scgr ste
Port D DAF; used tD choose the cloch sokce 1f
ob o0l DDoDo ) CL0 (SD0 =00, then the counfu
stop if Clod - cso0 have valucs
portB =OX55 betudeen ooi 1o1, ttie osc+llatog t uset
cock&owece aud he tinute Couktee
acts Case, tthe uers
ae oftun uitd for twt delay qeueiticns,
pORt D =DXAts
Brt D ’ FoCo FoRce Coupare mafeb
ATmiga 3d. ti mee
Can be' wed while qeutial1n
Waitina ! to cause the wdare qenet odor
actas a conepared mathuhad
OCCured
bit 5 ct portc, 4 DG DS DD3 D2
to. poRtB.othewTse
3- poiti fo co EM|COM) Coy WGM CS02(so cso q.
Port C-’ |p OXOO;
Port B ’olp oXFF;
port D olp ’ OXFF
niero controllee ths,TCNTOTatgaas chon
Prog w fa above
TCCRO (Tiinelcoute coutio l acqstu)
TCCR ís ah
forl coutiol of The bt of
PEe DDRC 0xo0 ; chown in above.
Port C 0Xoo
DDRB =0x FFj COd- Csoo Timer Zero el
PertBFF
bBRD z0XFF5 These bitk n the TccRO aeoi sta
Port D DAFF; uced to choose thie cloc5 sohce f
0Ol0D000 then the cOunte it
ECpinc f Clod-(so0 hare valucs
ports =0 X 55; betudein Ool 101, ttie osc llatog
as clockeouce aud +he tine /counte
acts Casc, tthe liuers
poRt D =DXAA;
are of tun uicd for tae delay qeucictins
3 BIt D ’ oCO FoRce Conp are hath
. ATmega sd. 4Tmee pro
Can be' wsed
to t
bohileCausesgentatig
while qtnsatiy
the ware
Jare
qeherator
HO a t a rf a concpared. mathU-had
OCCured
8) et an. AVa.
W e program to Convut packed
AVA. C
BcD Ox29 to AsCIN and. diplay thc bn
WGMO0 Tir
WG MD)
D6 D3 at mao (vord)
Normal
CTelclear timer ON Con Ohsincd chas d, 4;
Dusthned chas mydata =c
O i p M Phase corrccE DDB= DDRC =oXFF;
Fast 'PaM.
PortB =
portc
Port B =d|oxBo;
y= mydata f oxFO:
D5 e D4 bit 1
poat c Yl30;
Dt a Called as compare olp mode.
These bitr ae uued. toi a enesatt,hae
forn, Wite An. AVRC progtam to Conveit: sCll
Cso tsol, cco0 thet PoRt B
to
packed BCD f dsplay
# ude'< avaD.h7
Timeao clock is Iat matn (Yofef)
le i Selector
OFFe1 to elock &ource
Unstqncel choe
Unsigmed cho nyadatai =bsgo4 ; myelata 2 DxO
eIk
cik l6 4 11= mydatai OxFF3
Oelern ad. clk BOurce
0.n 10 Prh (2och on
eafanal clock Souce bn To . PTn clon pn
Sttial Coanuniafüon ia Tmega 32
Sinlcx Trans mitler Receive
is parallel e Sen'al Sn parallal dala Half Transmitter
wmorelineo Dure .ustol tn Dnplea
tRansf Otten g or
transfe data to a erie ie Only Recieru Transmtu
few feet auwey sesParnlle
dlevtces tat
transter tachude phntere'R hadoaky each Full IT2amwittu Recicre
tables wtth may duplea
a Lot of dataCoin be transfemed t Receiy Taaunitu
ghot amt of túne b!
Dara lel the d tonce Canot be Tn data tasniss+oy f the data can be
4) To teanc fce a derce located ma teanietted and eceived, it is cuslen
metus awa taansmissí0u. ths (a Couttast to
the oala
Dn stas. CommMican Buneplest transnwis ron Bueh as prfnus ,ih
One bt ot a tue Ln CO utrast which the conuputu ouly send data
to ed
Duple tnsssiou Cau bc half Dr, ful
Serfal data comnoni Colio inscs mtthocs
duplex. clepencling wpou whethe or not
the' ata tansfer Can be glmultancowS
asynehronaus and. Lynehon0usi 1f daa is ttansnittled One way at tmt.
s aeferre d as half dup lea.
) The Synehrohous method transfers Dt tae data Can oo both wee at tthe
bloch of data at a tie, wheras the Same t m t .
Asyuehro nous mtdtransfersialingle bytt duplex
at a tue
o) Thue ale 3 tpes oftranmaSOns
Ofuowse ful dupla aequius, e oire
conducors for t e data lines One feY
1 Stnple. trasuissíon
Q. Half duple to tranSfer and ecve data Smultant Onsly
3. Fulí duplen.
Asynchronons Seríalcommdini caton anel
Data fravm Ing
The dlata coina ln at the se Ceiv lnq end of
the data tn a Sesal
Cesal dafa tAQfes i9 all
ît s difftult to make &tnse
Of the data uhless, te Sencu f Alhen th ue s no transfer the eig nal is
protD tol, HI4H which ís seferred as Mouk. he low
KtCCive aqiee on Set of Rules,'a
Qh how tue clata is pached whe aow a04
the
Giqual o s acfred as Spacc.
bits coustat, te a caaAatu e Noile that Hhe teawsmission be wis
data bea Stout bit space follouotd by do, he Lse
ttheb.Hae sest of the bits untl MsB icd+
e Flnaly the One stop bit tadicatia
qocs. entl of tae
Last tart
Timee Tis1 prestalo oplions
Cso Pars cala Desuipt50n
stoppc
A SuhchRonou Serral dota Cow mnhtCafe
) NO prescaliig
K widey wed for charat OATtuted
transglion, whte bloct oa+tuted data 64 X TtLf-6 4
tansfer the 8ynehoow me tth o . XT4L - S6
XTAL[- 102
Dh the asynehmow. method cac CheractG Eatuna tlhn
[s placed btw Btastp
called as franls
Flndna the vaues to be loccled uto the
Data framina for asnchrnous Commu timelie
-wicaons the olato
aae pached between Ctart Stop btt the 9) Calulate the perDd of the tinsu clock
atoays Lb+t but tie Stop the fosmula.
bit Con be
The stat bit s always zuol Low), the Hue tae Ptwse linp lies frequencu of hc
Stop bit Clock used fok the timei
choactuf f Bik framed O100o O0 2) Divide te desãe. tinme dela by TelocE.
ís framed Ltw the
start Git e Hhe This sauys how many ol ocK we heed
Stop bit 3) Putom 2Sb-n, whu
hote tuat the LsB s a.lwOys Reat frst kalue we 20t from stp 2
4) Convut tht tesult of step 3 to he
whec X1, k 4he initial Nalue to be
5) Set
Assumn a that thc ceystal frequenay of
ATmcqoa 32 wAtte a prDa to
eneuate a Souae wae wittu a pa
perioc ofo
12-5 ms pin poxt B. 3.
Caystal
.quae freaueny
wave
nCy 8MH2
l2.S See
OFF DN OFf.
Tcloce = 1 0.|2sec
TEttmer
Jy Desücd tuelelay
Lcloct o.l25Ws
DFF
l2.S z 6.ds b.2
o-l2s
2 2Sb-n =2S6SD
2ob ’ imal
OxCE ’ Hcaadecimal
ware nclude <"avti, h 's
Waile a asatéc cn.plopoftBPoinf
fut awc)
Cng sta! fitqutaay
Sa nue DPRB =DA FF j ’ olp pocnt
0,Dbser
PORt B= pot e 1<<PB 4;
Des üecl t t de lay = PT =6.2S
6. 062 S O-. 62
TetoE
Yod T dalay
3) QS6 - 1oD = lD6decr TCN TI H DX CI;
= C ’ Heda,
TccRIB DXDD;3’NDrmal od
Q. Wah a c pro to toggle ony tte pat B TCCRI 3 = 0Xol?
nolmal modee no psScaa while [ CTFR e (oxol< To V))=DI;
to Caeate . Assnme tL=8MH2
TCCRIB= D;
TIFR DKD[<CTOVI;
8. wste pogram to
= l6fDoD, yole
TetoLs D.l2SXID pmclala to creafe
ur caoice
TL TH
It Ox fFP 3E90
L6 b; t
+ 6SS3S-2tD=CI8Tu
TU
3mili seuonl
9) Teiotk = 10.12Ssec
2) Desaeed tiuc
Teo
oelag D.12SAD
1t 65535-n
4LS36
TCNTIH DXA2.
TeNTIL = ox 40
Wte a AYR progsans
to qeuuale Squae wave af
pln poet B.4 assuc t6e
t6 GRZ trequenly
ueny 8MHZ: Calalate the nealucg to
CieiaJ Aeg
be loles
Giveu ala
T=Tont Toff 2/.26 tz1253).2 S
T=TJ
TCNT z9
= 62. Sl
T= . S u
21.25s
AVk CC p&ogia. to genu ate a Squae
Wite a Avk
z lQS H2. on POrt Bi 4 PAGE NO. :
DAE:
&MR ong wttk paestalos qual to s6
Fcquenty
XTAL=
aicalo = S
Use t u o, o&mal mode
T=t T= T|2
T= =812. = 4 ms. Or time
off tine
Duúcd tae delay
Teloce
Peinaa ealaulaY
XTAL = MH
cloce
64X12Ss =ys
C
dt to
geneate Squate
wav Of
nema) mode f t frea
val of
F8eq uen y = IgOH2