Department of Computer Science and Information EngineeringNational Cheng Kung University, TAIWAN
HANEL
I/O BIT
MANIPULATION PROGRAMMINGI/O Ports and Bit Addressability(cont’)
Example 4-2Write the follow
ing programs.Create a square wave of 50% duty cycle on bit 0 of port 1.Solution:The 50% duty cycle means that the “on”and “off”state (or the highand low portion of the pulse) have the same length. Therefore, we toggle P1.0 with a time delay in between each state.
HERE:SETBP1.0 ;set tohigh bit 0 of port 1LCALLDELAY;call the delay subroutineCLRP1.0;P1.0=0LCALLDELAY
SJMPHERE;keep doing itAnother way to write the above program is:HERE:CPLP1.0 ;set tohigh bit 0 of port 1LCALLDELAY;call the delay subroutineSJMPHERE;keep doing it8051 P1.0