Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Author: Umut Berk Bilgiç
- * Bilkent University Computer Science - CS224 Lab 6
- * Following code demonstrates simple binary counting with variable speed
- * and orientation controls. PORTs are modifiable as long as they follow
- * the classic numbering scheme.
- */
- // decimal int to binary string conversion for use in
- // ... reverse/mirrored display.
- void decTo8BinStr(int value, char* output)
- {
- int i;
- for (i = 7; i >= 0; --i)
- {
- value = value >> 1;
- output[i] = (value & 1) + '0';
- }
- }
- // initialize variables for
- int i;
- const int max_count = 256;
- void main() {
- AD1PCFG = 0xFFFF; // set analog ports to digital
- DDPCON.JTAGEN = 0; // disable jtag
- TRISD = 0x0000; // make PORTD output
- TRISE = 0xFFFF; // make PORTE input
- PORTD = 0xFFFF; // init PORTD to all zeros
- // E4 not pressed: normal
- // E4 pressed: mirrored
- // ** E1: high speed
- // ** E3: low speed
- while(1) // main loop
- {
- for (i = 0; i < max_count; i++)
- {
- if (PORTEbits.RE4 != 0) // normal orientation
- PORTD = ~i; // set LEDs to current number
- else
- {
- char s[8];
- decTo8BinStr(i, s);
- PORTDbits.RD0 = ~(s[0] - '0');
- PORTDbits.RD1 = ~(s[1] - '0');
- PORTDbits.RD2 = ~(s[2] - '0');
- PORTDbits.RD3 = ~(s[3] - '0');
- PORTDbits.RD4 = ~(s[4] - '0');
- PORTDbits.RD5 = ~(s[5] - '0');
- PORTDbits.RD6 = ~(s[6] - '0');
- PORTDbits.RD7 = ~(s[7] - '0');
- }
- // select delays based on given inputs at PORTE
- if (PORTEbits.RE1 == 0)
- Delay_ms(250);
- else if (PORTEbits.RE3 == 0)
- Delay_ms(750);
- else
- Delay_ms(500);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement