0% found this document useful (0 votes)
104 views7 pages

Microcontroller Application Week 4: Self-Practice: Digital Input & Output

The document provides instructions for a microcontroller self-practice assignment involving digital input and output programs. It includes 5 programs to complete: 1) lighting an LED using digital output in hex format, 2) lighting individual LED pins, 3) creating a running light, 4) lighting an LED with a button, and 5) counting up using binary-coded decimal on a 7-segment display. Students are instructed to create a circuit in Proteus, rewrite the programs to fix errors, compile and run the programs on the circuit, and complete all five programs.

Uploaded by

piwanai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views7 pages

Microcontroller Application Week 4: Self-Practice: Digital Input & Output

The document provides instructions for a microcontroller self-practice assignment involving digital input and output programs. It includes 5 programs to complete: 1) lighting an LED using digital output in hex format, 2) lighting individual LED pins, 3) creating a running light, 4) lighting an LED with a button, and 5) counting up using binary-coded decimal on a 7-segment display. Students are instructed to create a circuit in Proteus, rewrite the programs to fix errors, compile and run the programs on the circuit, and complete all five programs.

Uploaded by

piwanai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Microcontroller Application

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.

Program 1 : Lighting LED


Digital Output (hex format)
#include

<18F4555.h> // PIC18F4550 HEADER FILE


#fuses XT, NOWDT, NOLVP, NOPROTECT // EXTERNAL CLOCK, NO
WATCH DOG TIMER, NO LOW VOLTAGE
#use delay (clock=4M) // 4 MHZ CRYSTAL

//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);
}

Program 2: Lighting LED


Digital Output Individual
Pin
#include <18F4550.h> // PIC18F4550 HEADER FILE
#fuses XT,NOWDT,NOLVP,NOPROTECT
#use_delay (clock=4M) // 4 MHZ CRYSTAL
//Main Program

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);

}
}

Program 4: Lighting LED


Digital Output with button
hex format
#include <18F4550.h> // PIC18F4550 HEADER FILE
#fuses XT,NOWDT,NOLVP,NOPROTECT
#use delay (clock=4M) // 4 MHZ CRYSTAL

//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.

#include <18f4550.h> //Header


file
#fuses HS, NOLVP, NOWDT,
NOPROTECT
#use delay (clock = 20M)
Void main()
{
Set_tris_d(0x00);
Output_d(0x00);
While(true)
{
//Count Up
output_d(0b00111111);//0
Delay_ms(700);
output_d(0b00000110);//1
Delay_ms(700);
output_d(0b01011011);//2
Delay_ms(700);
output_d(0b01001111);//3
Delay_ms(700);

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

You might also like