MTripoli is correct.
I recall reading a paper not so long ago written by a UNI professor regarding his concerns with all of this. Copy & paste to do assignments. Where's the world headed?
Anyhow here's a glimpse at some C code:
Not much more involved than BASIC. The help file in MikroC is great, if that fails then go and buy a book. If that fails too, then go and do some formal study.Code:/* 8-LED Knight Rider Scanner MCU: PIC16f877a Requirements: 1. Connect 8 leds to portC 2. 1 x push button to RB1 with pull up resistor 3. 4MHz XTAL Usage: Pressing the switch causes the leds to chase back & forth */ // Global scope variables char i = 0; // Direction of scan char j = 1; // Gen working var char k = 0; // Gen working var void main() { TRISA = 0x00; // PortA as output TRISB = 0x02; // RB1 to as input rest as out TRISC = 0x00; // PortC as output TRISD = 0x00; // PortD as output TRISE = 0x00; // PortE as output PORTC = 0x00; // Init port, all pins low // Infinite loop while(1) { if (PORTB == 0) // Button pressed? { PORTC = j; // Write to port delay_ms(100); // 100mS delay // Scan dir forward // if (i == 0) { j = (j << 1); // Shift bits left } // Scan backward // else { j = (j >> 1); // Shift right } // Toggle direction // k ++; // Inc counter if (k == 7) // Counter reached n val? { k = 0; // Reset i = ~i; // Toggle dir } } } }




Bookmarks