Rtk89
Newbie level 6
- Joined
- Nov 15, 2013
- Messages
- 12
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 85
Hi every one,
I would like to write a code to PIC16F1782 PIC which put a 8bit number on PORTB. I am working in MikroC
The numbers are stored in an array. There are two button are used for choose the actual value of the array.
I would like to use interrupts to handle the buttons, but still not working in spite of that i spent a lot of hours to solve it.
My code:
I would like to write a code to PIC16F1782 PIC which put a 8bit number on PORTB. I am working in MikroC
The numbers are stored in an array. There are two button are used for choose the actual value of the array.
I would like to use interrupts to handle the buttons, but still not working in spite of that i spent a lot of hours to solve it.
My code:
Code:
int select[9] = {0x00, 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};
int cnt = 1;
int flag = 0;
void Interrupt() {
if (INTF_bit){
INTE_bit = 0;
if (Button(&PORTA, 0, 1, 1)) // Button pressed on PortA.0
cnt ++;
if (cnt >= 9){
cnt = 1;}
INTF_bit = 0; // CLear INTF flag
flag = 1;
}
if (Button(&PORTA, 1, 1, 1)) { // Button pressed on PortA.1
cnt --;
if (cnt < 1){
cnt = 8;}
INTF_bit = 0; // Clear INTF flag
flag = 1;
}
}
void main() {
ANSELA = 0;
ANSELB = 0;
TRISA = 0xff; //PORTA.0, PORTA.1 is input
TRISB = 0; //PORTB is output
TRISC = 0;
PORTB = 0xFF;
GIE_bit = 1;
PEIE_bit = 0;
INTE_bit = 1;
INTEDG_bit = 1;
do{
if(flag==1){ // Interrupt
LATB = select[cnt];
flag = 0; //Reset flag
INTE_bit = 1; //Re-enable External interrupt
}
}while(1);
}