Microcontroller Application Week 4: Self-Practice: Digital Input & Output
Microcontroller Application Week 4: Self-Practice: Digital Input & Output
Week 4
Self-Practice : Digital
Input & Output
Instructions:
1. Create a microcontroller circuit by
using Proteus. Your circuit is based
on the requirement by the listed
programs.
2. Rewrite the programs provided in
this slide.
3. Please repair all the errors. ( Eg.
Correct Port, syntax, space,
punctuations and spelling.
4. Compile the programs and transfer it
to the Proteus circuit.
5. Complete all FIVE programs.
//Main Program
void main()
{
//Pin Configuration
set_tris_c(0x00);
set_tirs_d(0xff);
output_d(Ox00);
while(true)
{
//Program start here
output_d(0xff);
delay_ms(500);
output_d(0x00)
delay ms(500);
}
void main()
{
set_tris_d(0x00);
output d(0x00)
while(true)
{
//Program start here
output_high(PIN_D0);
delay_ms(1500);
output_high(PIN_C2;
delay_ms(1500);
output_high(PIN_D1);
delay ms(1500);
output_high(PIN_D4);
delay_ms(1500);
ouput_d(0x00);
delay_ms(1500);
}
}
Program 3: Creating
Running Light
#include <18f4550.h> //Header file
#fuses HS, NOLVP, NOWDT, NOPROTECT// Hardware configuration
#use delay (clock = 20M)
Void main()
{
Set_tris_d(0x00);
Output_d(0x00);
While(true)
{
//Running Light
Output_d(0x01);
Delay_ms(100)
Output_d(0x02);
Delay_ms(100);
Output_d(0x04)
Delay_ms(100);
Output_d(0x08);
Delay_ms(100);
Output_d(0x10);
Delay_ms(100);
Ouput_d(0x20);
Dely_ms(100);
Output_d(0x40);
Delay_ms(100);
Output_d(0x80);
Delay_ms(100);
}
}
//Main Program
void main()
{
set_tris_d(0x00);
output_d(0x00);
while(true)
{
//Program start here
if(!input(PIN_A2))
{
output_d(0xff);
delay_ms(700);
output_d(0x00);
delay_ms(700);
output_d(0xff);
delay_ms(700);
output_d(0x00);
delay_ms(700);
}
}
}
Program 5: Count Up
(Using BCD)
The output of this program is shown using 7
Segment BCD. Please refer Reference 1.
output_d(0b01100110);//4
Delay_ms(700);
output_d(0b01101101);//5
Delay_ms(700);
output_d(0b01111101);//6
Delay_ms(700);
output_d(0b00000111);//7
Delay_ms(700);
output_d(0b01111111);//8
Delay_ms(700);
output_d(0b01101111);//9
Delay_ms(700);
}
}
Reference 1 :
Example Proteus
Circuit
In Proteus, search for 7 Segment
Display, Common Cathode, Green,
Red or Blue