Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xc.h>
- #include <pic12f617.h>
- #pragma config WRT=OFF //Disable write protection
- #pragma config FOSC=INTOSCIO //Use internal clock, with I/O on clock pins.
- #pragma config MCLRE=OFF //Use MCLRE as an input pin.
- #pragma config WDTE=OFF //Disable Watchdog Timer
- #pragma config IOSCFS=4MHZ //Run at 4MHz
- #pragma config CP=OFF //No code protection
- #pragma config PWRTE=OFF //Enable Power-Up-Timer
- #pragma config BOREN=OFF //Disable Brownout reset
- char transmit_codes[5] = {0b1000, 0b1001, 0b1010, 0b1011, 0b1100};
- void transmit(char code)
- {
- char value = transmit_codes[code]; //Copy the code
- //Output bit 4
- if((value & 0b1000) == 0)
- GPIO = 0x00;
- else
- GPIO = 0x01;
- _delay(50000);
- //Output bit 3
- if((value & 0b100) == 0)
- GPIO = 0x00;
- else
- GPIO = 0x01;
- _delay(50000);
- //Output bit 2
- if((value & 0b10) == 0)
- GPIO = 0x00;
- else
- GPIO = 0x01;
- _delay(50000);
- //Output bit 1
- if((value & 0b1) == 0)
- GPIO = 0x00;
- else
- GPIO = 0x01;
- _delay(50000);
- GPIO = 0;
- }
- void interrupt isr(void)
- {
- INTCONbits.GPIF = 0; //Clear flag.
- INTCONbits.GPIE = 0; //Disable interrupts to avoid triggering twice.
- _delay(10000); //Can probably scrap this now.
- return;
- }
- void main()
- {
- WPU = 0xFF; //Enable all pull-up resistors.
- GPIO = 0; //Clear all pins.
- ANSEL = 0; //All pins digital inputs, rather than analogue.
- TRISIO = 0b11111110; //RB0 output, others inputs.
- OPTION_REG = 0; //Enable pull-ups globally.
- INTCON = 0b10001000; //Enable global and GPIO change interrupts.
- IOC = 0b11111110; //Enable interrupt-on-change for all pins.
- while(1)
- {
- if(GPIObits.GP1 == 0)
- transmit(0);
- else if(GPIObits.GP2 == 0)
- transmit(1);
- else if(GPIObits.GP3 == 0)
- transmit(2);
- else if(GPIObits.GP4 == 0)
- transmit(3);
- else if(GPIObits.GP5 == 0)
- transmit(4);
- while((GPIO &= 0b00111110) != 0b00111110); //Wait for button to be released.
- INTCONbits.GPIE = 1; //Re-enable interrupts before sleeping.
- SLEEP();
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment