Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <18F27K40.h>
- #fuses NOMCLR RSTOSC_HFINTRC_1MHZ CLKOUT NOWDT NOPROTECT NOCPD
- #use delay(internal=64MHZ, clock_out)
- #define forever 1 // forever is true
- struct IOPort_Definition1
- { // 1st structure
- int unused_A; // Unused pins RA0..RB7
- int ExperimentSelect:4; // Pins RB0..3 for selection
- int unused_B:4; // rest of RB
- int1 Single_Bit_LED; // Pin RC0 LED used for single-bit indication
- int unused_C:7; // Remaining bits of Port C;
- };
- struct IOPort_Definition2
- { // 2nd structure
- int unused_A; // unused A's for 2nd structure
- int ExpSelect:4; // Pins RB0..3 for selection
- int unused_B:4; // rest of RB
- int fourbitOutput:4; // Pin RC0..3 LED
- int unused_C:4; // Remaining bits of Port C;
- };
- struct IOPort_Definition1 IO_Port;
- struct IOPort_Definition1 IO_Direction;
- struct IOPort_Definition2 IO_Port_Def2;
- struct IOPort_Definition1 IO_Direction_Def2;
- //struct IOPort_Definition1 IO_Latch;
- #byte IO_Port = 0xF8D // PORTA register in SFR
- #byte IO_Direction = 0xF88 // TRISA register
- //#byte IO_Latch = 0xF83
- void main(void) {
- IO_Direction.unused_A = 0b00000000; // all unused outputs
- IO_Direction.ExperimentSelect = 0b1111; // Pins RA4..7 as output
- IO_Direction.unused_B = 0b0000; // Pins RB0..7
- IO_Direction.Single_Bit_LED = 0b0; // Single LED as output
- IO_Direction.unused_C = 0b0000000; // Unused pins as output
- port_a_pullups(0xFF);
- port_b_pullups(0xFF);
- setup_oscillator(OSC_HFINTRC_64MHZ);
- while(forever)
- {
- switch (IO_Port.ExperimentSelect)
- {
- case 0b0000:
- {
- IO_Port.Single_Bit_LED = 0b0; // Toggle single LED
- break;
- }
- case 0b1000:
- {
- IO_Port.Single_Bit_LED = ! IO_Port.Single_Bit_LED; // Toggle single LED
- delay_ms(500); //delays for 0.5 second before restarting loop
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement