You are on page 1of 40

CECS 347 PROGRAMMING in C SYLABUS

Writing C Code for the 8051


by Matthew Kramer (Available on-line at: http://ubermensch.org/Computing/8051/8051-c/#appa) About the Keil Compiler Keil Software (http://www.keil.com) publishes one of the most complete development tool suites for 805 software! which is used throu"hout industr#. $or development of % code! their &eveloper's Kit product includes their %5 compiler! as well as an inte"rated 805 simulator for debu""in". ( demonstration version of this product is available on their website! but it includes several limitations (see ne)t section). *his is the software that will be used for %+%S,-./. *he % pro"rammin" lan"ua"e was desi"ned for computers! thou"h! and not embedded s#stems. 0t does not support direct access to re"isters! nor does it allow for the readin" and settin" of sin"le bits! two ver# important re1uirements for 805 software. 0n addition! most software developers are accustomed to writin" pro"rams that will b# e)ecuted b# an operatin" s#stem! which provides s#stem calls the pro"ram ma# use to access the hardware. 2owever! much code for the 805 is written for direct use on the processor! without an operatin" s#stem. *o support this! the Keil compiler has added several e)tensions to the % lan"ua"e to replace what mi"ht have normall# been implemented in a s#stem call! such as the connectin" of interrupt handlers. *he purpose of this manual is to further e)plain the limitations of the Keil compiler! the modifications it has made to the % lan"ua"e! and how to account for these in developin" software for the 805 micro controller. Keil Limitations *here are several ver# important limitations in the evaluation version of Keil's &eveloper's Kit that users need be aware of when writin" software for the 805 . Object code must be less than 2 Kb tes *he compiler will compile an#,si3ed source code file! but the final ob4ect code ma# not e)ceed 5 Kb#tes. 0f it does! the linker will refuse to create a final binar# e)ecutable (or 2+6 file) from it. (lon" the same lines! the debu""er will refuse an# files that are over 5Kb#tes! even if the# were compiled usin" a different software packa"e.

$ew student pro4ects will cross this 5Kb#te threshold! but pro"rammers should be aware of it to understand wh# code ma# no lon"er compile when the pro4ect "rows too lar"e. !rogram code starts at address 0"#000 (ll % code compiled and linked usin" the Keil tools will be"in at address 0).000 in code memor#. Such code ma# not be pro"rammed into devices with less than 7Kb#tes of 8ead,9nl# :emor#. %ode written in assembl# ma# circumvent this limitation b# usin" the ;ori"in; ke#word to set the start to address 0)0000. <o such work,around e)ists for % pro"rams! thou"h. 2owever! the inte"rated debu""er in the evaluation software ma# still be used for testin" code. 9nce tested! the code ma# be compiled b# the full version of the Keil software! or b# another compiler that supports the % e)tensions used b# Keil. C $odifications *he Keil % compiler has made some modifications to an otherwise (<S0, compliant implementation of the % pro"rammin" lan"ua"e. *hese modifications were made solel# to facilitate the use of a hi"her,level lan"ua"e like % for writin" pro"rams on micro controllers. %ariable & pes *he Keil % compiler supports most % variable t#pes and adds several of its own. 'tandard & pes *he evaluation version of the Keil % compiler supports the standard (<S0 % variable t#pes! with the e)ception of the floatin",point t#pes. *hese t#pes are summari3ed below. & pe char unsigne# char enum short unsigne# short int unsigne# int long

Bits 8 8 1$ 1$ 1$ 1$ 1$ %

Bytes Range 1 1 -1 8 to !1 " 0 to 55 -% &"$8 to !% &"$" -% &"$8 to !% &"$" 0 to $5&5%5 -% &"$8 to !% &"$" 0 to $5&5%5 ' - &1'"&'8%&$'8 to

! &1'"&'8%&$'" unsigne# long % ' 0 to '& ('&$("& (5

0n addition to these variable t#pes! the compiler also supports the struct and union data structures! as well as t#pe redefinition usin" typedef. Keil & pes *o support a micro controller and embedded s#stems applications! Keil added several new t#pes to their compiler. *hese are summari3ed in the table below.

& pe bit sbit s)r s)1$

Bits 1 1 8 1$

Bytes Range 0 0 1 0 to 1 0 to 1 0 to 55 0 to $5&5%5

9f these! onl# the bit t#pe works as a standard variable would. *he other three have special behavior that a pro"rammer must be aware of. bit *his is a data t#pe that "ets allocated out of the 805 's bit,addressable on,chip 8(:. =ike other data t#pes! it ma# be declared as either a variable. 2owever! unlike standard % t#pes! if ma# not be used as a pointer. (n e)ample of its usa"e follows.
/> declare two bit variables , the compiler will decide which >/ /> addresses the# are at. 0nitiali3e them to 0 and . >/ bit testbit ? 0@ bit testbit5 ? @ /> set testbit to the value in testbit5 >/ testbit ? testbit5@ /> clear testbit5 >/ testbit5 ? 0@ /> testbit is now a ! and testbit5 is now a 0 >/ /> <ote that the assi"nment of testbit5 to testbit onl# copied >/ /> the contents of testbit5 into testbit . 0t did >not> chan"e >/ /> the location of testbit to be the same as testbit5. >/

sbit( sfr( and sf1)

*hese are special t#pes for accessin" ,bit! 8,bit! and 7,bit special function re"isters. Aecause there is no wa# to indirectl# address re"isters in the 805 ! addresses for these variables must be declared outsite of functions within the code. 9nl# the data addressed b# the variable ma# be manipulated in the code. (n e)ample follows:
/> create an sbit variable that points to pin 0 of port /> note that this is done outside of an# functionsB >/ sbit C 0 ? 0)D0@ >/

/> now the functions ma# be written to use this location >/ void main (void) E /> forever loop! to""lin" pin 0 of port >/ while ( ?? ) E C 0 ? BC 0@ dela# (500)@ /> wait 500 microseconds >/ F F

%onvenientl#! the standard special function re"isters are all defined in the re"5 .h file that an# developer ma# include into their source file. 9nl# re"isters uni1ue to the particular 805 ,derivative bein" used for the pro4ect need have these variable declared! such as re"isters and bits related to a second on,chip serial port. Keil %ariable *"tensions 0n writin" applications for a t#pical computer! the operatin" s#stem handles mana"es memor# on behalf of the pro"rams! eliminatin" their need to know about the memor# structure of the hardware. +ven more important! most computers havin" a unified memor# space! with the code and data sharin" the same 8(:. *his is not true with the 805 ! which has separate memor# spaces for code! on,chip data! and e)ternal data. *o accommodate for this when writin" % code! Keil added e)tensions to variable declarations to specif# which memor# space the variable is allocated from! or points to. *he most important of these for student pro"rammers are summari3ed in the followin" table. *"tension $emor & pe #ata i#ata ,#ata co#e +elated A'$

*irectl+-a##ressable #ata memor+ (#ata ./0 A& 0"-h memor+ a##resses 0,00-0,"-) 1n#irectl+-a##ressable #ata memor+ (#ata memor+ a##resses 0,00-0,--) 3,ternal #ata memor+ 6rogram memor+ ./0 20& #080h ./0 A& 20 ./04 5*672 ./0C 5A!*672

*hese e)tensions ma# be used as part of the variable t#pe in declaration or castin" b# placin" the e)tension after the t#pe! as in the e)ample below. 0f the memor# t#pe e)tension is not specified! the compiler will decide which memor# t#pe to use automaticall#! based on the memor# model (S:(==! %9:C(%*! or =(8G+! as specified in the pro4ect properties in Keil).
/> *his is a function that will calculate and return a checksum of >/ /> a ran"e of addresses in code memor#! usin" a simple al"orithm >/ /> that simpl# adds each consecutive b#te to"ether. *his could be >/ /> useful for verif#in" if the code in 89: "ot corrupted (like if >/ /> the $lash device were wearin" out). >/ unsi"ned int checksum (unsi"ned int start! unsi"ned int end) E /> first! declare pointers to the start and end of >/ /> the ran"e in code memor#. >/ unsi"ned int code >codeptr! >codeend@ /> now declare the variable the checksum will be >/ /> calculated in. Aecause direct,addressable data >/ /> is faster to access than indirect! and this >/ /> variable will be accessed fre1uentl#! we will >/ /> declare it in data memor# (instead of idata). >/ /> 0n realit#! if left unspecified! the compiler >/ /> would probabl# leave it in the accumulator for >/ /> even faster access! but that would defeat the >/ /> point of this e)ample. >/ unsi"ned int data checksum ? 0@ /> 0nitiali3e the codestart and codeend pointers to >/ /> the addresses passed into the function as params. >/ /> because start and end are passed in as values! >/ /> not pointers! the# must be cast to the correct >/ /> pointer t#pe >/ codeptr ? (unsi"ned int code >)start@ codeend ? (unsi"ned int code >)end@ /> <ow perform the checksum calculation! loopin" >/ /> until the end of the ran"e is reached. >/ while (codeptr H? codeend) E checksum ? checksum I (unsi"ned int data)>codeptr@ codeptrII@ /> "o to the ne)t address >/ F return (checksum)@ F

Keil ,unction *"tensions (s in most other % compilers! functions ma# be declared in one of two fashions:
unsi"ned int functionname (unsi"ned int var) E .... return (var)@ F functionname (var) unsi"ned int var E .... return (var)@ F

:ost modern pro"rammers use the first s#nta)! as do the e)amples in this document.

Keil provides two important e)tensions to the standard function declaration to allow for the creation of interrupt handlers and reentrant functions. interrupt 0n writin" applications for a t#pical computer! the operatin" s#stem provides s#stem calls for settin" a function! declared in the standard manner! as the handler for an interrupt. 2owever! in writin" code for an 805 without an operatin" s#stem! such a s#stem would not be possible usin" solel# % code. *o eliminate this problem! the Keil compiler implements a function e)tension that e)plicitl# declares a function as an interrupt handler. *he e)tension is interrupt! and it must be followed b# an inte"er specif#in" which interrupt the handler is for. $or e)ample:
/> *his is a function that will be called whenever a serial >/ /> interrupt occurs. <ote that before this will work! interrupts >/ /> must be enabled. See the interrupt e)ample in the appendi). >/ void serialJint (void) interrupt . E ... F

0n the e)ample! a function called serial_int is set as the handler for interrupt .! which is the serial port interrupt. *he number is calculated b# subtractin" - from the interrupt vector address and dividin" b# 8. *he five standard interrupts for the 805 are as follows: -nterrupt 3,ternal 0 7imer 0 3,ternal 1 7imer 1 9erial %ector address 000%h 0008h 001%h 0018h 00 %h % ' -nterrupt number 0 1

9ther interrupts are dependent on the implementation in the particular 805 , derivative bein" used in the pro4ect! but ma# be calculated in the same manor usin" the vector addresses specified b# the manufacturer. using Since the processor onl# save the current pro"ram counter before e)ecutin" an interrupt handler! the handler can potentiall# dama"e an# data that was in the re"isters prior to the interrupt. *his in turn would corrupt the pro"ram once the processor "oes back to where it left off. *o avoid this! the Keil compiler

determines which re"isters will be used b# the interrupt handler function! pushes them out to the stack! e)ecutes the handler! and then restores the re"isters from the stack! before returnin" to the interrupted code. 2owever! this incurs e)tra time! especiall# if a lot of re"isters will be used. 0t is preferred that as little time be spent in interrupts as possible. *o decrease this time! Keil provides an optional e)tension! using! to the interrupt e)tension that tells the compiler to simple chan"e to a new re"ister bank prior to e)ecutin" the handler! instead of pushin" the re"isters to the stack.
/> *his is a function that will be called whenever a serial >/ /> interrupt occurs. Crior to e)ecutin" the handler! the >/ /> processor will switch to re"ister bank void serialJint (void) interrupt . usin" E ... F

0n the 805 ! interrupts have two possible priorities: hi"h and lo. 0f! durin" the processin" of an interrupt! another interrupt of the same priorit# occurs! the processor will continue processin" the first interrupt. *he second interrupt will onl# be processed after the first has finished. 2owever! if an interrupt of a hi"her priorit# arrives! the first (low priorit#) interrupt will itself be interrupted! and not resume until the hi"her priorit# interrupt has finished. Aecause of this! all interrupts of the same priorit# ma# use the same re"ister bank. *he using e)tension should be used when 1uick e)ecution time is of hi"h importance! or when other functions are called from the interrupt handler! as it would otherwise push all of the re"isters on to the stack prior to callin" the function! incurrin" more time penalties. reentrant Similar to the case described for interrupts above! it is possible for a sin"le function to be interrupted b# itself. $or e)ample! in the middle of normal e)ecution of the function! the interrupt occurs! and that interrupt makes a call to the same function. Khile the interrupt handler will save the re"isters before enterin" this function! no protective measures are taken from overwritin" the contents of local variables allocated in data memor#. Khen the interrupt is serviced and control is passed back to normal e)ecution! the corrupted data in those variables could ruin the entire pro"ram. *he "eneral term for a function that ma# be called more than once simultaneousl# is ;reentrant.; (ccordin"l#! the reentrant e)tension ma# be used in a function declaration to force the compiler to maintain a separate data area in memor# for each instance of the function. Khile safe! this does have the potential to use lar"e area of the rather limited data memor#. (n e)ample of such a function follows.

/> Aecause this function ma# be called from both the main pro"ram >/ /> and an interrupt handler! it is declared as reentrant to >/ /> protect its local variables. >/ int somefunction (int param) reentrant E ... return (param)@ F /> *he handler for +)ternal interrupt 0! which uses somefunction() >/ void e)ternal0Jint (void) interrupt 0 E ... somefunction(0)@ F /> the main pro"ram function! which also calls somefunction() >/ void main (void) E while ( ?? ) E ... somefunction()@ F F

Appendi" A . 'ample Code Sample code that is full# compilable in the evaluation version of Keil ma# be found at the followin" L8=: http://ubermensch.or"/%omputin"/805 /code

Sample Code
+)ample code for the 805 :icrocontroller basic.c , ( ver# basic e)ample of writin" % code for the 805 . int.c , ( rewrite of the serial e)ample to use interrupts in %. serial.c , +)ample of how to read and write data on the 805 serial port usin" pollin".

Example 1 BASIC.C
/>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > basic.c , *he basics of writin" % code for the 805 usin" the Keil > development environment. 0n this case! a simple pro"ram will be > constructed to make a binar# counter on Cort 0. >/ /> > (s alwa#s with %! the included header files should come first. :ost > ever# pro4ect for the 805 will want to include the file re"5 .h. *his > header file contains the mappin" of re"isters to names! such as settin" > C0 (port 0) to address 0)80. *his allows the coder to use the ke#word > ;C0; in their code whenever the# wish to access Cort 0. $or the complete > list of re"isters named! view the file. >/ Minclude /> > 9ther header files ma# be included after re"5 .h! includin" an# headers > created b# the user. >/ /> > *he % pro"ram starts with function main(). 0n the case of a pro"ram > written usin" multiple .c files! main can onl# occur in one of them. > Lnlike in pro"rammin" user applications for a standard computer! the > main() function in a Keil pro"ram for the 805 takes no inputs and > returns no output! thus the declaration has implied void t#pes. >/ />>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > main , Cro"ram entr# point >

> 0<CL*: </( > 8+*L8<S: </( >/ main() E unsi"ned int i@

/> will be used for a dela# loop >/

/> $irst! Cort 0 will be initiali3ed to 3ero >/ C0 ? 0@ /> > <ow the counter loop be"ins. Aecause this pro"ram is intended > to run in an embedded s#stem with no user interaction! and will > run forever! the rest of the pro"ram is placed in a non,e)itin" > while() loop. >/ while ( ?? ) E /> > *his is a ver# unpredictable method of implementin" a dela# > loop! but remains the simplest. :ore reliable techni1ues > can be done usin" the usin" the built,in timers. 0n this > e)ample! thou"h! the for() loop below will run throu"h 70000 > iterations before continuin" on to the ne)t instruction. > *he amount of time re1uired for this loop varies with the > clock fre1uenc# and compiler used. >/ for (i ? 0@ i H 70000@ iII) E@F /> 0ncrement Cort 0 >/ C0 ? C0 I @ F F

Example 2 I !.C
/>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > int.c , ( demonstration of how to write interrupt,driven code for an > 805 usin" the Keil % compiler. *he same techni1ues ma# work in other > 805 % compilers with little or no modifcation. *his pro"ram will > combine the functionalit# of both basic.c and serial.c to allow serial > communications to be entirel# in the back"round! driven b# the serial > interrupt. *his allows the main() function to count on Cort 0 without > bein" aware of an# on"oin" serial communication. >/ /> included headers >/ Minclude

/> function declarations >/ char "et%haracter (void)@ void send%haracter (char)@ /> read a character from the serial port >/ /> write a character to the serial port >/

/> > 0nterrupt handlers: > 2ere the code for the interrupt handler will be placed. 0n this > e)ample! a handler for the serial interrupt will be written. > +)amination of the 805 specs will show that the serial interrupt is > interrupt .. ( sin"le interrupt is "enerated for both transmit and > receive interrupts! so determination of the e)act cause (and proper > response) must be made within the handler itself. > *o write an interrupt handler in Keil! the function must be declared > void! with no parameters. 0n addition! the function specification > must be followed b# a specification of the interrupt source it is > attached to. *he ;usin"; attribute specifies which re"ister bank > to use for the interrupt handler. >/ void serialJint (void) interrupt . E static charchr ? 'N0'@ /> character buffer >/ /> > *he interrupt was "enerated! but it is still unknown wh#. $irst! > check the 80 fla" to see if it was because a new character was > received. >/ if (80 ?? ) /> it was a receive interrupt >/ E chr ? SAL$@ /> read the character into our local buffer >/ 80 ? 0@ /> clear the received interrupt fla" >/ *0 ? @ /> si"nal that there's a new character to send >/ F else if (*0 ?? ) /> otherwise! assume it was a transmit interrupt >/ E *0 ? 0@ /> clear the transmit interrupt fla" >/ if (chr B? 'N0') /> if there's somethin" in the local buffer... >/ E if (chr ?? 'Nr') chr ? 'Nn'@ /> convert to >/ SAL$ ? chr@ /> put the character into the transmit buffer >/ chr ? 'N0'@ F F F /> functions >/ />>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > main , Cro"ram entr# point. *his pro"ram sets up the timers and > interrupts! then simpl# receives characters from the serial port and > sends them back. <otice that nowhere in the main function is Cort 0

> incremented! nor does it call an# other function that ma# do so. > main() is free to do solel# serial communications. Cort 0 is handled > entirel# b# the interrupt handler (aside from initiali3ation). > > 0<CL*: </( > 8+*L8<S: </( >/ main() E /> Aefore the serial port ma# be used! it must be confi"ured. >/ /> Set up *imer 0 for the serial port >/ S%9< ? 0)50@ *:9& ? 0)50@ *2 ? 0)$+@ +*0 ? 0@ *8 ? @ *0 ? @ /> mode ! 8,bit uart! enable receiver >/ /> timer ! mode 5! 8,bit reload >/ /> reload value for 5.00 baud >/ /> we don't want this timer to make interrupts >/ /> start the timer >/ /> clear the buffer >/

/> > *he compiler automaticall# installs the interrupt handler! so > all that needs to be done to use it is enable interrupts. $irst! > speficiall# enable the serial interrupt! then enable interrupts. >/ +S ? @ +( ? @ /> allow serial interrupts >/ /> enable interrupts >/

/> initiali3e Cort 0 to 0! as in basic.c >/ C0 ? 0@ /> > =oop forever! increasin" Cort 0. ("ain! note nothin" is done > with the serial port in this loop. Oet simulations will show > that the software is perfectl# capable of maintainin" serial > communications while this countin" proceeds. >/ while ( ?? ) E unsi"ned int i@ for (i ? 0@ i H 70000@ iII) E@F /> dela# >/ C0 ? C0 I @ /> increment Cort 0 >/ F F

Example " SERIA#.C


/>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > serial.c , ( demonstration of how to access the serial port on an > 805 usin" % code. *o avoid usin" interrupts! this e)ample polls > the interrupt fla"s in the serial port to know when the serial port > is read#.

>/ /> included headers >/ Minclude /> re"ister names >/ /> > function declarations , 2ere the functions in our code are declared. > 0n %! this is onl# necessar# if the actual implementation of the > function is performed in a separate file or after an# function that > calls it in its own file. 0n this pro"ram! these functions will > all be implemented within this file. 2owever! for asthetics! > functions will be implemented in order of hi"hest,level to lowest. > A# nature! this creates a scenario where the functions will be > called b# code placed above the actual implementation! so the > functions must first be declared here. >/ char "et%haracter (void)@ void send%haracter (char)@ /> functions >/ />>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > main , Cro"ram entr# point. *his pro"ram will simpl# receive characters > from the serial port! then send them back. > > 0<CL*: </( > 8+*L8<S: </( >/ main() E char chr@ /> variable to hold characters in >/ /> Aefore the serial port ma# be used! it must be confi"ured. >/ /> > *he serial controll re"ister confi"ures the method of operation > for the serial port. *he value used below is 0)50 (or 50h in > 805 lin"o)! referrin" to the bits within the S%9< re"ister! > this does the followin": > :9&+ ? 0 0 (8,bit L(8* serial buffer! no stop bit , this is t#pical) > 8+< ? (enabled receivin") > *A8! 8A8 ? 00 (unused in this mode) > 80!*0 ? 00 (start the interupt fla"s as read# to receive and send) >/ S%9< ? 0)50@ /> mode ! 8,bit uart! enable receiver >/ /> read a character from the serial port >/ /> write a character to the serial port >/

/> > Aecause a standard serial port transmits no clockin" si"nal! both > ends of the serial connection must a"ree on a clock fre1uenc#! > which is then "enerated internall# at each end. $or this e)ample! > a baud rate of 5.00 bits per second will be used. *he timer must be > confi"ured accordin"l#.

> *he formula for determinin" the reload value based on desired baud > rate and clock fre1uenc# is: > *2 ? 557 , clock fre1uenc# (in 23) / (-8. > baud rate) > $or 5.00bps and a .05:h3 clock: > *2 ? 557 , !050!000 / (-8. > 5.00) ? 555 ? 0)$+ >/ *:9& ? 0)50@ *2 ? 0)$+@ /> timer ! mode 5! 8,bit reload >/ /> reload value for 5.00 baud >/

/> Settin" *8 will start the timer! and serial communications >/ *8 ? @

/> > Set the *ransmit 0nterrupt fla" to send the the character in > the serial buffer! clearin" it for use b# the pro"ram. >/ *0 ? @ /> > <ow the pro"ram isr ead# to send and receive data on the serial > port. Aecause it is "oin" to do this indefinitel# (until the > device is effectivel# turned off)! the rest of the pro"ram will > be in an infinite while() loop. >/ while ( ?? ) E /> read the ne)t character from the serial port >/ chr ? "et%haracter ()@ /> send it back to the ori"inal sender >/ send%haracter (chr)@ F F />>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > "et%haracter , Kaits for a new character to arrive in the serial port! > then reads it. > > 0<CL*: </( > 8+*L8<S: newl# received character >/ char "et%haracter (void) E char chr@ /> variable to hold the new character >/ /> > Kait until the serial port si"nals a new character has arrived. > 0t does so b# settin" the 8eceived interrupt fla"! 80! which

> this routine loops on until it is set to . *his is known > as pollin". >/ while (80 B? ) E@F /> now read the value in the serial buffer into the local variable >/ chr ? SAL$@ /> > 9nce the character is read! the serial port must be told that it is > free to receive a new character. *his is done b# clearin" the > 8eceived 0nterrupt fla". >/ 80 ? 0@ /> the character is then returned to the callin" function. >/ return(chr)@ F />>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > send%haracter , Kaits until the serial port is read# to send a new > character! then sends it. > > 0<CL*: > chr , *he character to send > > 8+*L8<S: </( >/ void send%haracter ( char chr /> character to send >/ ) E /> > Aecause of the wa# terminal pro"rams for serial ports work! we want > to replace carria"e returns with line feeds. >/ if (chr ?? 'Nr') chr ? 'Nn'@ /> > Kait until the serial port si"nals the previous character has > been sent. 0t does so b# settin" the *ransmit interrupt fla"! *0! > which this routine loops on until it is set to . >/ while (*0 B? ) E@F /> > %lear the *ransmit 0nterrupt fla" to prepare the serial port > to send a new character.

>/ *0 ? 0@ /> Krite the character into the serial port buffer re"ister! SAL$ >/ SAL$ ? chr@ /> > *he serial port hardware takes over from here! and the pro"ram > ma# continue with other operations. >/ return@ F

Example $ % Implementing a $ bit Counter using an &'(1 and Interfacing it to an #C)


*rof. +ran, -a.id
*urpose% 0n this lab! #ou will learn how to write a simple % pro"ram for 80%5 micro, controller! compile it usin" %5 compiler! and emulate it on an emulator usin" Cro5 . *he pro"ram will be used to control a simple .,bit up,down counter! capable of countin" from 0 to 5. (t each step the count should be displa#ed in decimal format on the =%&. Assignment% 0n this lab :

:ou ;ill #esign a '-bit <p-*o;n counter using the C programming language )or the 8051 micro-controller an# #ispla+ the count on an =C*. :ou ;ill then test an# run +our program on the 8051. 7he ' bit counter has the )ollo;ing )unctionalit+: o 7he counter has the )ollo;ing input pins : a. Reset : ;hen high resets the counter dataout to >>0000?? b. Updown : #eci#es ;hether the counter counts up or #o;n. c. Load : ma@es the counter count )rom the ' bit input Datain #. Datain : ;hich is a ' bit input count o 7he counter has a ' bit Dataout to re)lect the count. o 7he count has to be sent to the =C* an# #ispla+e# in #ecimal )ormat. Apparatus Re/uired%
1. 2. 3.

'."@ resistors(8) 1@ resistor(1) *16 s;itch

4. 5. 6.

=C* 50 po;er suppl+ 6hilips 6*951 #evelopment boar# A

Sc.ematic%

*rogram%
Mpra"ma S:(== &A 9+ Minclude Minclude ;io.h; /> C0! C ! C5 and C- are predefined port names and are bit addressable >/ sbit reset ? C0P.@ /> bit . of Cort 0 >/ sbit upJdown ? C0P5@

sbit load ? C0P7@ sbit StartJ=%& ? C0P/@ /> bit / of Cort - >/ /> &ela# function >/ void dela#() E int i! 4@ for(i?0@ iH 000@ iII) for(4?0@ 4H 00@ 4II) i ? i I 0@ F /> $unction to output the decimal value of the count on the =%& >/ void Crint0nt(unsi"ned char i) E char chQ.R@ /> Krite code to convert the count to a strin" value and use the CrintStrin" function provided in io.c >/ CrintStrin"(ch)@ F void main(void) E unsi"ned char count ? 0@ 0nit09()@ /> 0nitiali3e the =%& >/ while ( ) E if (StartJ=%& ?? ) E %learScreen()@ CrintStrin"(;8ead#...;)@ dela#()@ F else if (reset ?? ) E /> 9utput 0 on the =%& >/ F else if (load ?? ) E /> 9utput the current value of &atain on the =%& >/ F else E /> %heck the Lp/&own pin for or 0 count up or down accordin"l#. &ispla# each value on the =%& >/ F F F

Steps to be follo0ed%

Bire up the circuit as sho;n in the schematic. Note: 6ort 0 shoul# not be use# )or output because it #oes cannot su))icientl+ #rive the =C*. 8. .ap +our net;or@ #rive to
7. C:NNCeartNcs 55 9. 2un 10.

the batch )ile cs1 .bat Cet the 1/ )iles to control the =C*. 7he )unctions speci)ie# in these )iles are use# to han#le initialiDation an# other special )unctions o) the =C*.

o io.c o io.h 2. /pen up a */9 ;in#o; an# e#it +our program un#er C: -or eg:
3. 4. 5. 6. %:N*empNcount.c

Compile +our programs


c5 count.c c5 io.c

7his ;oul# generate obEect )iles: count.obE& io.obE


7. 8.

=in@ the obEect )iles to create +our e,ecutable )ile.


bl5 count.ob4! io.ob4 to count.omf

Example ( % Implementing a Calculator 1sing *erip.erals #i,e a 2eypad and #C)


Crof. $rank Sahid
*urpose% 0n this lab! #ou will build a simple calculator usin" the ke#pad as an input and the =%& as an output peripheral. (fter debu""in" and testin" #our pro"ram! #ou will have to burn the compiled pro"ram to a standalone 805 chip at the end of this lab. )escription% Ke#pads are often used as a primar# input device for embedded micro controllers. *he ke#pads actuall# consist of a number of switches! connected in a row/column arran"ement as shown in $i" . 0n order for the micro controller to scan the ke#pad! it outputs a nibble to force one (onl# one) of the columns low and then reads the rows to see if an# buttons in that column have been pressed. *he rows are pulled up b# the internal weak pull,ups in the 805 ports. %onse1uentl#! as lon" as no buttons are pressed! the micro controller sees a lo"ic hi"h on each of the pins attached to the ke#pad

rows. *he nibble driven onto the columns alwa#s contains onl# a sin"le 0. *he onl# wa# the micro controller can find a 0 on an# row pin is for the ke#pad button to be pressed that connects the column set to 0 to a row. *he controller knows which column is at a 0,level and which row reads 0! allowin" it to determine which ke# is pressed. $or the ke#pad! the pins from left to ri"ht are: 8 ! 85! 8-! 8.! % ! %5! %-! %..

+ig 1. 2eypad connection

Assignment% 0n this lab :

:ou ;ill #esign a integer calculator ;ith a @e+pa# input. :our #esign shoul# be able to rea# the operan#s (integers 0 to () an# the operator )rom the @e+pa#. :ou can #esign an+ combination o) the input seFuence as +ou li@e. -or e,ample& +ou ma+ ;ish to input in the ;a+: 1. pic@ the )irst operan# . pic@ the operator %. pic@ the secon# operan#

Apparatus Re/uired% 1. . %. '. 5. $. 1@ resistor(1) @e+pa# =C* 1 .GD Cr+stal 50 po;er suppl+ 6hilips 6*951 #evelopment boar#

". 6rogrammer =C6454'0 Sc.ematic%

*rogram%
/> *o implement a inte"er calculator usin" a ke#pad and =%& >/ Mpra"ma S:(== &A 9+ Minclude Hre"5 .hT Minclude ;io.h; /> *he functions to initiali3e and control the =%& are assumed to be in the file io.c >/ /> $unction to output the decimal value of the result on the =%& >/ void Crint0nt(int i) E .

. . F /> 8outine to scan the ke# pressed >/ unsi"ned char ke#Jscan() E unsi"ned char i! 4! temp ! temp5@ while( ) /> keep waitin" for a ke# to be pressed >/

for(i?0@ iH.@ iII) E /> Set each row to 0 >/ C ? 0)ff U V( HHi)@ /> Scan each column to see which ke# was pressed >/ for (4?.@ 4H8@ 4II) E /> %ode to determine the position of the ke# which was pressed >/ /> return(position) >/ F F F void main() E /> Oou can have a conversion table to convert the ke# position into a valid number which indicates the operator or operand value. $or e": the numbers 0 to D are valid operands and 00 to 0- denote addition! subtraction! multiplication and division respectivel# >/ char convJtableQR ? E ! 5! -! .! 5! 7! /! 8! D! , ! 0! , ! 00 /> add >/! 0 /> sub >/! 05 /> mul >/! 0- /> div >/

F@ char num ! num5! op@ int result@ 0nit09()@ while( ) E %learScreen()@ /> read num >/ Goto6O(0! 0)@ CrintStrin"(;num : ;)@ do E num ? convJtableQke#Jscan()R@ F

while( num H 0 WW num T D )@ /> read a valid operation >/ Goto6O(0! 0)@ CrintStrin"(;op : ;)@ do E op ? convJtableQke#Jscan()R@ F while( op H 00 )@ /> read num5 >/ Goto6O(0! 0)@ CrintStrin"(;num5 : ;)@ do E num5 ? convJtableQke#Jscan()R@ F while( num5 H 0 WW num5 T D )@ /> compute result >/ if( op ?? 00 ) E /> (dd numbers and displa# result on the =%& >/ F else if( op ?? 0 ) E . . . . /> %ontinue similarl# for other operations >/ F F F

Example 3 % Serial Communication


*rof. +ran, -a.id
*urpose% *o establish a serial communication link between the C% and the 805 . )escription% Serial communication is often used either to control or to receive data from an embedded microprocessor. Serial communication is a form of 0/9 in which the bits of a b#te be"in transferred appear one after the other in a timed se1uence on a sin"le wire. Serial communication has become the standard for intercomputer communication. 0n this lab! we'll tr# to build a serial link between 805 and C% usin" 8S5-5.

RS2"2C *he e)ample serial waveforms in $i" show the waveform on a sin"le conductor to transmit a b#te (0). ) seriall#. *he upper waveform is the **=,level waveform seen at the transmit pin of 805 . *he lower waveform shows the same waveform converted to 8S5-5% levels. *he volta"e level of the 8S5-5% are used to assure error,free transmission over "reater distances than would be possible with **= levels. (s shown in $i" ! each b#te is preceded b# a start bit and followed b# one stop bit. *he start and stop bits are used to s#nchroni3e the serial recivers. *he data b#te is alwa#s transmitted least-significant-bit first. $or error checkin" it is possible to include a parit# bit as well! 4ust prior to the stop bit. *he bits are transmitted at specific time intervals determined b# the baud rate of the serial si"nal. *he baud rate is the reciprocal of the time to send bit. +rror,free serial communication re1uires that the baud rate! number of data bits! number of stop bits! and presence or absence of a parit# bit be the same at the transmitter and at the receiver.

+ig 1. Serial 4a5eforms 1sing t.e Serial *ort 805 provides a transmit channel and a receive channel of serial communication. *he transmit data pin (*6&) is specified at C-. ! and the receive data pin (86&) is at C-.0. *he serial si"nals provided on these pins are **= si"nal levels and must be boosted and inverted throu"h a suitable converter(=* -0%< is used in this lab) to compl# with 8S5-5 standard. (ll modes are controlled throu"h S%9<! the Serial %9<trol re"ister. *he S%9< bits are defined as S:0! S: ! S:5! 8+<! *A8! 8A8! *0! 80 from :SA to =SA. *he timers are controlled usin" *:9&! the *imer :9&e re"ister! and *%9<! the *imer %9<trol re"ister.

Register )escriptions
S%9< bit definitions S%9< Serial %ontrol 8e"ister (msb) (lsb) ,,,,,,,,,,,,,,,,,,,,,,,,,,,,, WS:9WS: WS:5W8+<W*A8W8A8W*0W80W ,,,,,,,,,,,,,,,,,,,,,,,,,,,,, S:9! S: ! S:5 Serial :ode %9ntrol Aits S:0 S: :ode Aaud 8ate ,,,,,,,,,,,,,,,,,,,,,,, 0 0 0 fosc/ 5 0 variable 0 5 fosc/-5 or fosc/7. S:5 :ultiprocessor :ode %ontrol Ait ? :ulti,processor mode 0 ? <ormal mode 8+< 8eceiver +nable Ait ? 8eceive +nable 0 ? 8eceive &isabled *A8 Dth *ransmit Ait +nabled onl# in modes 5 and 8A8 Dth Ait 8eceived Lsed in modes 5 and 80! *0 Serial 0nterrrupts 80 is set to indicate receipt of a serial word and *0 is set to indicate completion of a serial transmission. ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, *:9& *imer :ode 8e"ister ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, WGateW%/*W: W:0WGateW%/*NW: W:0W ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, WH,*imer ,,,,TH,,,*imer 0 ,,,T Gate Gatin" %ontrol. 0? *imer enabled

? *imer enabled if 0<*)N is hi"h %/*N %ounter or *imer Selector 0 ? 0nternal count source (clock/ 5) ? +)ternal count source (*) pin) : ! :0 :ode %ontrol : :0 :ode ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 0 0 :ode 0! - bit count mode 0 :ode ! 7 bit count mode 0 :ode 5! (uto reload mode :ode -! :ultiple mode ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, *%9< *imer %ontrol 8eceiver 8e"ister ,,,,,,,,,,,,,,,,,,,,,,,,,,, W*$ W*8 W*$0W*80W W W W W ,,,,,,,,,,,,,,,,,,,,,,,,,,, H,*imer %ontrolsTH,Lnused for timers *8) *imer ) run control 0 ? *imer not runnin" ? *imer runnin" *$) *imer ) fla" 0 ? timer has not rolled over ? timer has rolled over ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, $ormula to load the value of *2 correspondin" to re1uired baud rate %lock $re1uenc# ( 5 :23) ,,,,,,,,,,,,,,,,,,,,,,, ? Aaud 8ate 5 ) -5 ) (557,*2 )

RS2"2 connector C%s have Dpin/55pin male SLA,& connectors. *he pin la#out is as follows (seen from outside #our C%):
5 JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ N ............. / N ..... / N ............ / N .... / ,,,,,,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,, . 55 7 D

JJJJJJJJJJJJJJJ

<ame (S5.) 55pin Dpin &ir $ull name 8emarks ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, *)& 5 - o *ransmit &ata 8)& - 5 i 8eceive &ata 8*S . / o 8e1uest *o Send %*S 5 8 i %lear *o Send &*8 50 . o &ata *erminal 8ead# &S8 7 7 i &ata Set 8ead# 80 55 D i 8in" 0ndicator &%& 8 i &ata %arrier &etect G<& / 5 , Si"nal "round , , , Crotective "round &on't use this one for si"nal "roundB

7he most important lines are 2,*& 7,*& an# CH*. /thers are use# ;ith mo#ems& printers an# plotters to in#icate internal states.

Apparatus Re/uired% 1. . %. '. 5. 0.1 - capacitors($) =711%0CH connector an# cable 50 po;er suppl+ 6hilips 6*951 #evelopment boar# Sc.ematic%

*rogram%
Mpra"ma S:(== &A 9+

Minclude Hre"5 .hT unsi"ned char 8eceiveSerial() E unsi"ned char c@ *:9& ? 0)50@ /> confi"ure timer for the correct baud rate >/ *2 ? 0)e7@ /> 500 bps for 5 :23 clock >/ *%9< ? 0)00@ /> Set timer to not runnin" >/ S%9< ? 0)50@ /> Set Serial 09 to receive and normal mode >/ *8 ? @ /> start timer to 8eceive >/ while( (S%9< U 0)0 ) ?? 0 ) /> wait for receive data >/@ c ? SAL$@ return c@ F void SendSerial(unsi"ned char c) E /> initiali3e..set values for *:9&! *2 and *%9< >/ /> set the *) interrupt in S%9< to indicate sendin" data >/ /> start timer >/ /> write character to SAL$ >/ /> wait for completion of sent data >/ F void main(void) E unsi"ned char c@ while( )E

/> Lse 8eceiveSerial to read in a character 'c' >/ /> &o some computation on 'c' >/ /> Send the result usin" SendSerial() >/ F F

Example 6 % Analog to )igital Con5ersion


*rof. +ran, -a.id
*urpose% *o be able to implement analo" to di"ital conversion usin" the (&%080.=%< 8, bit (/& converter. Oou will desi"n a circuit and pro"ram the chip so that when an analo" si"nal is "iven as input! the e1uivalent di"ital volta"e is displa#ed on an =%& displa#. *hus! in effect! #our circuit should function like a simple voltmeter. )escription% *he abilit# to convert analo" si"nals to di"ital and vice,versa is ver# important in si"nal processin". *he ob4ective of an (/& converter is to determine the output di"ital word correspondin" to an analo" input si"nal.

*he &atasheet for (&%080.=%< shows the pinout and a t#pical application schematic. *he (/& converter operates on the successive appro)imation principle. (nalo" switches are closed se1uentiall# b# successive,appro)imation lo"ic until the analo" differential input volat"eQS in(I) , Sin(,)R matches a volta"e derived from a tapped resistor strin" across the reference volta"e. *he normal operation proceeds as follows. 9n the hi"h,to,low transition of the K8 input! the internal S(8 latches and the shift,re"ister sta"es are reset! and the 0<*8 output will be set hi"h. (s lon" as the %S input and K8 input remain low! the (/& will remain in a reset state. %onversion will start from to 8 clock periods after at least one of these inputs makes a low,to,hi"h transition. (fter the re1uisite number of clock pulses to complete the conversion! the 0<*8 pin will make a hi"h,to,low transition. *his can be used to interrupt a processor! or otherwise si"nal the availabilit# of a new conversion. ( 8& operation(with %S low) will clear the 0<*8 line hi"h a"ain. *he device ma# be operated in the free, runnin" mode b# connectin" 0<*8 to the K8 input with %S?0. Since this is an 8,bit (/& converter! a volta"e from 0,5S. 9 will be repersented as 0000 0000 (0 in decimal) and 5S is represented as (557 in decimal). *o convert a value 6 volts to decimal! use the followin" formula:
6 > 5.0 ,,,,,,, 557

7o get a better resolution& an# #ispla+ the vlaue as a )loating point number& +ou can multipl+ the numerator b+ a )actor o) 100& 1000 etc. an# then print the voltage accor#ingl+. Apparatus Re/uired% 1. . %. '. A*C080'=CH 10@ resistor 1@ resistor 50 po;er suppl+

Sc.ematic% 8efer to the pinout and the application e)ample in the &atasheet to connect the (&%080.. *he =%& can be connected as was done in the earlier labs.

+igure 1. Connection )iagram

+igure 2. !ypical Applications

+igure ". A7) Sc.ematic

*rogram%
Minclude Hre"5 .hT Minclude ;io.h; sbit 8+(& ? C-P5@ /> &efine these accordin" to how #ou have connected the >/ sbit K80*+ ? C-P-@/> 8&! K8! and 0<*8 pins >/ sbit 0<*8 ? C-P.@ void main( void ) E unsi"ned char adSal@ unsi"ned lon" volts@ 0nit09()@ 8+(& ? @ K80*+ ? @ 0<*8 ? @ %learScreen()@ while( ) E

/> :ake a low,to,hi"h transition on the K8 input >/ while( 0<*8 ?? )@ /> wait until the 0<*8 si"nal makes >/ /> hi"h,to,low transition indicatin" >/ /> completion of conversion >/ /> 8ead the volta"e value from the port >/ 8+(& ? 0@ adSal ? C @ 8+(& ? @ /> %ompute the di"ital value of the volat"e read >/ /> Crint the value of the volta"e in decimal form >/ F F

Example & % Controlling a Stepper 8otor


*rof. +ran, -a.id
*urpose% *he purpose of this lab is to control a stepper motor! with instructions received from the C% via a serial communication link to the 805 . )escription% Stepper motors are often used in con4unction with microcontrollers to provide precisel# controlled motor power. Stepper motors are devices that rotate a precise number of de"rees for each ;step; applied! as opposed to re"ular motors! which simpl# rotate continuousl# when power is applied. &rivin" a stepper motor involves appl#in" a series of volta"es to the four(t#picall#) coils of the stepper motor. *he coils are ener"i3ed one or two at a time to cause the motor to rotate one step. Assignment% 0n this lab! #ou'll desi"n a pro"ram to do the followin" 4obs: 1. 9et up the stepper motor an# stepper motor #river circuit . 1nter)ace the 6C to the 8051 through a serial communication lin@. Control the movement o) the stepper motor b+ characters receive# )rom the 6C. Bhen the character ?l? is receive# )rom the 6C& ma@e the stepper motor turn le)t. Also #ispla+ the message I.oving le)tI on an =C* inter)ace# to the 8051. Bhen the character ?r? is receive# )rom the 6C& ma@e the stepper motor turn in the opposite #irection an# the mesasge I.oving 2ightI shoul# be #ispla+e# on the =C*. Apparatus Re/uired%

1. .J3%0557 H6H transistors (') . .J3 (557 6H6 transistors (') %. .C%'"(6 9tepper motor #river '. =88 ""%-.1 8ipolar 9tepper .otor 5. 1@ resistors (() $. '"K resistor ". 0.1- capacitors ($) 8. 9erial communication cable& connectors (. =711%0CH 10. =C* 11. 50 po;er suppl+ 1 . 6hilips 6*951 #evelopment boar#

Sc.ematic%

-igure 1. 6inout )or transistors

-igure . 9tepper .otor 9chematic *rogram%


Mpra"ma S:(== &A 9+ Minclude Hre"5 .hT unsi"ned char 8eceiveSerial() E

unsi"ned char c@ *:9& ? 0)50@ /> confi"ure timer for the correct baud rate >/ *2 ? 0)e7@ /> 500 bps for 5 :23 clock >/ *%9< ? 0)00@ /> Set timer to not runnin" >/ S%9< ? 0)50@ /> Set Serial 09 to receive and normal mode >/ *8 ? @ /> start timer to 8eceive >/ while( (S%9< U 0)0 ) ?? 0 ) /> wait for receive data >/@ c ? SAL$@ return c@ F void SendSerial(unsi"ned char c) E /> initiali3e..set values for *:9&! *2 and *%9< >/ /> set the *) interrupt in S%9< to indicate sendin" data >/ /> start timer >/ /> write character to SAL$ >/ /> wait for completion of sent data >/ F void main(void) E unsi"ned char c@ while( )E

/> Lse 8eceiveSerial to read in a character >/ /> &ependin" on character make the motor move left or ri"ht >/ /> and displa# the direction on the =%& >/ F F

Steps to be follo0ed% 1. 9et up the circuit )or the stepper motor as sho;n in the above schematic. Hote that the circuit reFuires t;o #i))erent voltages but +ou nee# a common groun#. CAUTION: Transistors can get very hot. . 1nter)ace the =C* an# 8051 as ;as #one in earlier labs. 6ins % an# 5 o) the =C* are connecte# to #i))erent pins on the 8051. :ou ;ill nee# to ma@e the appropriate changes to the io.c )ile. %. 9et up serial communication bet;een the 6C an# 8051. !ee Lab " and ma#e the appropriate changes.$ '. 7he stepper motor moves ;hen Cl@ (pin " on the .C%'"(6 chip) is toggle#. 1t?s #irection #epen#s on ;hether CB/CCB (pin 10 on the .C%'"(6 chip) is set to 0 or 1. 5. 2un +our program on the emulator. 7o transmit #ata go to Heighborhoo# Het;or@ -L 6eart -L cs1 -L 9erial Cop+ the e,ecutable onto +our #es@top

3nter the letter +ou ;ish to transmit an# clic@ I7ransmitI several times. 1) ever+thing is #one correctl+& +our stepper motor shoul# be moving.

*rogram I9.C
Mpra"ma S:(== &A 9+

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

Minclude Hre"5 .hT Minclude ;io.h;

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

sfr &(*(JALS ? 0)a0@ sbit 8S ? 0)b0@ sbit + ? 0)b @

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

static void +nable=%&(int t) E

unsi"ned char i@

+ ? @ for(i?0@ iHt@ iII) i ? i@ + ? 0@ for(i?0@ iHt@ iII) i ? i@ F

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

void 0nit09(void) E

8S?0@ &(*(JALS?0)-8@ +nable=%&(555)@ &(*(JALS?0)-8@ +nable=%&(555)@ &(*(JALS?0)-8@ +nable=%&(555)@ &(*(JALS?0)0 @ +nable=%&(555)@ &(*(JALS?0)0d@ +nable=%&(555)@ &(*(JALS?0)07@ +nable=%&(555)@ 8S ? @ F

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

void %learScreen(void) E

8S?0@ &(*(JALS?0)0 @ +nable=%&(555)@ 8S ? @ F

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

void Goto6O(unsi"ned char r! unsi"ned char c) E

8S?0@ &(*(JALS?0)05@ +nable=%&(555)@ for(r?r>.0Ic! c?0@ cHr@ cII)

&(*(JALS ? 0) .! +nable=%&(.5)@ 8S? @ F

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

void Cut%har(char c) E

&(*(JALS ? c@ +nable=%&(.5)@ F

/>,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>/

void CrintStrin"(const char> s) E

while( >s ) &(*(JALS ? >(sII)! +nable=%&(.5)@ F

*rogram ..c

#ifndef __io_h__ #define __io_h__

#define HIDE_CURSOR

0,25

oid Ini!IO" oid#$ oid C%e&'S('een" oid#$ oid )o!o*+",n-i.ned (h&' ', ,n-i.ned (h&' (#$

oid /,!Ch&'"(h&' (#$ oid /'in!S!'in."(on-! (h&'0 -#$

#endif

You might also like