Mini Project ไฟจราจรจำลอง
อุปกรณ์
1. PIC16F628A
2. 7SEGMENT common cathode
3. IC 7SEGMENT 7448
4. LED green,red,yellow
5. CAPACITOR 22pF
6. CRYSTAL 4MHz
7. แหล่งจ่ายไฟ 5 V
Code
void three(void);
void twenty (void);
void thirty (void);
void main()
{
TRISA = 0x00;
TRISB = 0x00;
PORTB = 0;
while(1)
{
thirty ();
three ();
twenty ();
three ();
}
}
void three (void)
{
PORTB= 0b00110010; //3
delay_ms(500);
PORTB= 0b00100010; //2
delay_ms(500);
PORTB= 0b00010010; //1
delay_ms(500);
PORTB= 0b00000010; //0
}
void twenty (void)
{
PORTA=0b00000011; //R2 GR1
PORTB= 0b00001000; //20
delay_ms(500);
PORTB= 0b10010100; //19
delay_ms(500);
PORTB= 0b10000100; //18
delay_ms(500);
PORTB= 0b01110100; //17
delay_ms(500);
PORTB= 0b01100100; //16
delay_ms(500);
PORTB= 0b01010100; //15
delay_ms(500);
PORTB= 0b01000100; //14
delay_ms(500);
PORTB= 0b00110100; //13
delay_ms(500);
PORTB= 0b00100100; //12
delay_ms(500);
PORTB= 0b00010100; //11
delay_ms(500);
PORTB= 0b00000100; //10
delay_ms(500);
PORTB= 0b10010000; //9
delay_ms(500);
PORTB= 0b10000000; //8
delay_ms(500);
PORTB= 0b01110000; //7
delay_ms(500);
PORTB= 0b01100000; //6
delay_ms(500);
PORTB= 0b01010000; //5
delay_ms(500);
PORTB= 0b01000000; //4
delay_ms(500);
PORTB= 0b00110000; //3
delay_ms(500);
PORTB= 0b00100000; //2
delay_ms(500);
PORTB= 0b00010000; //1
delay_ms(500);
PORTB= 0b00000000; //0
PORTA =0;
}
void thirty (void)
{
PORTA=0b0001100 ; //GR2 R1
PORTB= 0b00001100; //30
delay_ms(500);
PORTB= 0b10011000; //29
delay_ms(500);
PORTB= 0b10001000; //28
delay_ms(500);
PORTB= 0b01111000; //27
delay_ms(500);
PORTB= 0b01101000; //26
delay_ms(500);
PORTB= 0b01011000; //25
delay_ms(500);
PORTB= 0b01001000; //24
delay_ms(500);
PORTB= 0b00111000; //23
delay_ms(500);
PORTB= 0b00101000; //22
delay_ms(500);
PORTB= 0b00011000; //21
delay_ms(500);
PORTB= 0b00001000; //20
delay_ms(500);
PORTB= 0b10010100; //19
delay_ms(500);
PORTB= 0b10000100; //18
delay_ms(500);
PORTB= 0b01110100; //17
delay_ms(500);
PORTB= 0b01100100; //16
delay_ms(500);
PORTB= 0b01010100; //15
delay_ms(500);
PORTB= 0b01000100; //14
delay_ms(500);
PORTB= 0b00110100; //13
delay_ms(500);
PORTB= 0b00100100; //12
delay_ms(500);
PORTB= 0b00010100; //11
delay_ms(500);
PORTB= 0b00000100; //10
delay_ms(500);
PORTB= 0b10010000; //9
delay_ms(500);
PORTB= 0b10000000; //8
delay_ms(500);
PORTB= 0b01110000; //7
delay_ms(500);
PORTB= 0b01100000; //6
delay_ms(500);
PORTB= 0b01010000; //5
delay_ms(500);
PORTB= 0b01000000; //4
delay_ms(500);
PORTB= 0b00110000; //3
delay_ms(500);
PORTB= 0b00100000; //2
delay_ms(500);
PORTB= 0b00010000; //1
delay_ms(500);
PORTB= 0b00000000; //0
PORTA =0;
}
คลิปการทำงาน