Dengan menggunakan microcontroller, pattern nyalaan lampu LED boleh di kawal secara automatik sepenuhnya mengikut kehendak cita rasa pengguna.
SOURCE CODE : KAEDAH 1
------------------------------------------------------------------------------------------------------------
#include <18F4620.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT
#use delay (clock=20M)
#define LED1_ANODE PIN_C0 // LED 1 COMMON ANODE
#define LED2_ANODE PIN_C1 // LED 2 COMMON ANODE
#define LED3_ANODE PIN_C2 // LED 3 COMMON ANODE
#define LED4_ANODE PIN_C3 // LED 4 COMMON ANODE
#define LED5_ANODE PIN_C4 // LED 5 COMMON ANODE
#define LED6_ANODE PIN_C5 // LED 6 COMMON ANODE
#define LED7_ANODE PIN_C6 // LED 7 COMMON ANODE
#define LED8_ANODE PIN_C7 // LED 8 COMMON ANODE
#define LED1_CATHODE PIN_D0 // LED 1 COMMON CATHODE
#define LED2_CATHODE PIN_D1 // LED 2 COMMON CATHODE
#define LED3_CATHODE PIN_D2 // LED 3 COMMON CATHODE
#define LED4_CATHODE PIN_D3 // LED 4 COMMON CATHODE
#define LED5_CATHODE PIN_D4 // LED 5 COMMON CATHODE
#define LED6_CATHODE PIN_D5 // LED 6 COMMON CATHODE
#define LED7_CATHODE PIN_D6 // LED 7 COMMON CATHODE
#define LED8_CATHODE PIN_D7 // LED 8 COMMON CATHODE
#define BUTTON1 PIN_B0 // PRESET BUTTON 1
#define BUTTON2 PIN_B1 // PRESET BUTTON 2
#define BUTTON3 PIN_B2 // PRESET BUTTON 3
#define BUTTON4 PIN_B3 // PRESET BUTTON 4
void main()
{
set_tris_b(0xFF); // SET ALL PORT B AS INPUT PORT
set_tris_c(0x00); // SET ALL PORT C AS OUTPUT PORT
set_tris_d(0x00); // SET ALL PORT D AS OUTPUT PORT
output_b(0xFF); // RESET PORT B
output_c(0xFF); // RESET PORT C
output_d(0x00); // RESET PORT D
while(TRUE) // always repeat program
{
output_high(LED1_ANODE);
output_high(LED2_ANODE);
output_high(LED3_ANODE);
output_high(LED4_ANODE);
output_high(LED5_ANODE);
output_high(LED6_ANODE);
output_high(LED7_ANODE);
output_high(LED8_ANODE);
output_low(LED1_CATHODE);
output_low(LED2_CATHODE);
output_low(LED3_CATHODE);
output_low(LED4_CATHODE);
output_low(LED5_CATHODE);
output_low(LED6_CATHODE);
output_low(LED7_CATHODE);
output_low(LED8_CATHODE);
delay_ms(500); // wait for 500m seconds
output_low(LED1_ANODE);
output_low(LED2_ANODE);
output_low(LED3_ANODE);
output_low(LED4_ANODE);
output_low(LED5_ANODE);
output_low(LED6_ANODE);
output_low(LED7_ANODE);
output_low(LED8_ANODE);
output_high(LED1_CATHODE);
output_high(LED2_CATHODE);
output_high(LED3_CATHODE);
output_high(LED4_CATHODE);
output_high(LED5_CATHODE);
output_high(LED6_CATHODE);
output_high(LED7_CATHODE);
output_high(LED8_CATHODE);
delay_ms(500); // wait for 500m seconds
}
}
------------------------------------------------------------------------------------------------------------
SOURCE CODE : KAEDAH 2
----------------------------------------------------------------------------------------------------------------------------------
#include <18F4620.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT
#use delay (clock=20M)
#define LED1_ANODE PIN_C0 // LED 1 COMMON ANODE
#define LED2_ANODE PIN_C1 // LED 2 COMMON ANODE
#define LED3_ANODE PIN_C2 // LED 3 COMMON ANODE
#define LED4_ANODE PIN_C3 // LED 4 COMMON ANODE
#define LED5_ANODE PIN_C4 // LED 5 COMMON ANODE
#define LED6_ANODE PIN_C5 // LED 6 COMMON ANODE
#define LED7_ANODE PIN_C6 // LED 7 COMMON ANODE
#define LED8_ANODE PIN_C7 // LED 8 COMMON ANODE
#define LED1_CATHODE PIN_D0 // LED 1 COMMON CATHODE
#define LED2_CATHODE PIN_D1 // LED 2 COMMON CATHODE
#define LED3_CATHODE PIN_D2 // LED 3 COMMON CATHODE
#define LED4_CATHODE PIN_D3 // LED 4 COMMON CATHODE
#define LED5_CATHODE PIN_D4 // LED 5 COMMON CATHODE
#define LED6_CATHODE PIN_D5 // LED 6 COMMON CATHODE
#define LED7_CATHODE PIN_D6 // LED 7 COMMON CATHODE
#define LED8_CATHODE PIN_D7 // LED 8 COMMON CATHODE
#define BUTTON1 PIN_B0 // PRESET BUTTON 1
#define BUTTON2 PIN_B1 // PRESET BUTTON 2
#define BUTTON3 PIN_B2 // PRESET BUTTON 3
#define BUTTON4 PIN_B3 // PRESET BUTTON 4
void main()
{
set_tris_b(0xFF); // SET ALL PORT B AS INPUT PORT
set_tris_c(0x00); // SET ALL PORT C AS OUTPUT PORT
set_tris_d(0x00); // SET ALL PORT D AS OUTPUT PORT
output_b(0xFF); // RESET PORT B
output_c(0xFF); // RESET PORT C
output_d(0x00); // RESET PORT D
while(TRUE) // always repeat program
{
output_c(0xFF); // all led at port c OFF
output_d(0x00); // all led at port d OFF
delay_ms(500); // wait for 500m seconds
output_c(0x00); // all led at port c ON
output_d(0xFF); // all led at port d ON
delay_ms(500); // wait for 500m seconds
}
}
------------------------------------------------------------------------------------------------------------
LITAR SIMULASI
VIDEO SIMULASI
No comments:
Post a Comment