Schematic Diagram Circuit |
Output_d(PORTD);
Delay_ms(100);
}
PORTD=0x80;
For(int
j=0;j<=7;j++)
{
PORTD=PORTD>>1;
Output_d(PORTD);
Delay_ms(100);
}
}
}
Exercise 4:
Source Code:
//*********************************************************
//*********************************************************
//Exercise 4 : Count Up
#include <18f4550.h> //Header file
#fuses HS, NOLVP, NOWDT, NOPROTECT // Hardware configuration
#use delay (clock = 20M)
//Define LEDs
#define LED1 PIN_D0
#define LED2 PIN_D1
#define LED3 PIN_D2
#define LED4 PIN_D3
#define LED5 PIN_D4
#define LED6 PIN_D5
#define LED7 PIN_D6
#define LED8 PIN_D7
//Main Function
Void main()
{
//Set
PORTD as output
Set_tris_d(0x00);
//set_tris_d(0b00000000);
//Initialize
PORTD
Output_d(0x00);
//output_d(0b00000000);
While(true)
{
//Count
Up
output_d(0b00111111);//0
Delay_ms(100);
output_d(0b00000110);//1
Delay_ms(100);
output_d(0b01011011);//2
Delay_ms(100);
output_d(0b01001111);//3
Delay_ms(100);
output_d(0b01100110);//4
Delay_ms(100);
output_d(0b01101101);//5
Delay_ms(100);
output_d(0b01111101);//6
Delay_ms(100);
output_d(0b00000111);//7
Delay_ms(100);
output_d(0b01111111);//8
Delay_ms(100);
output_d(0b01101111);//9
Delay_ms(100);
}
}
Exercise 5:
Source Code:
//*********************************************************
//Exercise 5 : Button
#include <18f4550.h> //Header file
#fuses HS, NOLVP, NOWDT, NOPROTECT // Hardware configuration
#use delay (clock = 20M)
//Define LEDs
#define LED1 PIN_D0
#define LED2 PIN_D1
#define LED3 PIN_D2
#define LED4 PIN_D3
#define LED5 PIN_D4
#define LED6 PIN_D5
#define LED7 PIN_D6
#define LED8 PIN_D7
//Define Button
#define BUTTON1 PIN_B0
#define BUTTON2 PIN_B1
//Main Function
Void main()
{
//Set
PORTD as output
Set_tris_d(0x00);
//set_tris_d(0b00000000);
//Set
PORTB as input
Set_tris_b(0xff);
//set_tris_b(0b11111111);
//Initialize
PORTD
Output_d(0x00);
//output_d(0b00000000);
While(true)
{
If(!input(BUTTON1))
//Press Button1
{
//7Segment ON
output_d(0b00111111);//0
Delay_ms(100);
}
Else
{
//7Segment
OFF
output_d(0b00000000);//0
Delay_ms(100);
}
}
}
No comments:
Post a Comment