Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*--------------------------------------------------------/
- Name : Mohd Syahri Fikri Bin Samusi
- LCD interfacing with PIC16F877A
- with RB interrupt. switch RB7 will count up
- and switch RB6 will count down. Range of
- counter from 250 to 300
- Date modified : 06 April 2012
- /--------------------------------------------------------*/
- #include <htc.h>
- #include <pic16f877a.h>
- #define _XTAL_FREQ 20000000
- #include <lcd.c>
- int k;
- //----Interrupt Service function----
- interrupt ISR(void) // Interrupt function definition
- {
- if(RBIF) // if RB port change interrupt flag
- {
- RBIE = 0; // Disable RB port change interrupt
- if(!RB7)
- {
- k++; // Increment of the counter
- //__delay_ms(1000); //Delay for 1 second
- }
- if(!RB6)
- {
- k--; // Decrement of the counter
- //__delay_ms(1000); //Delay for 1 second
- }
- RBIF = 0; // Reset RB port change interrupt flag
- RBIE = 1; // Re-enable RB port change interrupt
- }
- GIE=1;
- }
- //----Main function----
- void main( )
- {
- char j[6];
- lcd_init( );
- TRISB = 0xF0;
- nRBPU = 0;
- lcd_putch ('\f');
- lcd_putc ("RB7 UP, RB6 DOWN ");
- RBIE = 1; // Enable the RB port change interrupt
- GIE = 1; // Global interrupt enable
- RBIF = 0; // Clear RB port change interrupt flag
- PEIE = 1; // Peripheral Interrupt Enable
- while (1)
- {
- if(k<250) k=250;
- if(k>300) k=300;
- // k++;//Increment the counter
- j[0]=k/10000+'0';
- j[1]=(k%10000)/1000+'0';
- j[2]=(k%1000)/100+'0';
- j[3]=(k%100)/10+'0';
- j[4]=k%10+'0';
- j[5]=0;
- lcd_gotoxy(2,0); //Go to the second line of LCD panel
- lcd_putc ("Now is ");
- lcd_putc (j);
- __delay_ms(1000); //Delay for 1 second
- }
- }
- //End of Program
Advertisement
Add Comment
Please, Sign In to add comment