Setup:
Connect GP0, GP1, and GP2 (pins 7, 6, and 5 of PIC12F683) to LEDs 3, 2, and 1 respectively.
Connect GPIO2, 1, 0 pins to LEDs 1, 2, 3 using jumper wires.
Software:/*
PIC12F683 Experiment Board
Experimen No. 1 : 3-bit Up Counter
"LEDs 1, 2, and 3 are connected to GPIO2, GPIO1, and GPIO0
respectively"
*/
short i;
void main() {
CMCON0 = 7;
TRISIO = 8; // GPIO0-GPIO2 are Outputs
ANSEL = 0;
GPIO = 0;
delay_ms(500);
i=0;
do {
GPIO=i;
delay_ms(1000);
i = i+1;
if(i == 8) i=0;
}while(1);
}
Output:
3 LEDs count up to 7, then reset and count starts again.
0 comments:
Post a Comment