alpha91
Full Member level 3
Hi all, I am creating a system that allow LED to light up in few different mode.
microcontroller = 16F628A
compiler = MikroC
my PIC microcontroller also connected to 16x2 LCD to display current mode.
This program currently have a problem that everytime i changed the mode with INT, the result only reflect after one full cycle. Is there anyway to make it change right after i pressed the INT button?
I tried to use reset so that it can scan the condition (set in EEPROM in this case) but i fail to compile the asm code.
my code is as below:
microcontroller = 16F628A
compiler = MikroC
my PIC microcontroller also connected to 16x2 LCD to display current mode.
This program currently have a problem that everytime i changed the mode with INT, the result only reflect after one full cycle. Is there anyway to make it change right after i pressed the INT button?
I tried to use reset so that it can scan the condition (set in EEPROM in this case) but i fail to compile the asm code.
my code is as below:
Code:
// Mode change for LED
// LED output at B3
// INT button at B0
int mode1;
int modecount;
signed int i = 0;
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
char message1[] = "Mode 1";
char message2[] = "Mode 2";
char message3[] = "Mode 3";
char message4[] = "Unicorn Banshee HG";
void main()
{
CMCON = 0x07;
TRISA = 0; // To configure PORTC as output port
TRISB = 0x01;
OPTION_REG.INTEDG = 1; // Set Rising Edge Trigger for INT
INTCON.GIE = 1; // Enable The Global Interrupt
INTCON.INTE = 1; // Enable INT
PWM1_Init(5000); // Initialize PWM frequency
PWM1_Set_Duty(127);
PWM1_Start();
mode1 = 0x00;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // OFF cursor
Lcd_Cmd(0x01); // Clear display
Lcd_Cmd(0x03); //cursor home
while(1)
// Loop:
{
if( eeprom_read(0) == 0x01) // Mode2
{
Lcd_out(1,1,message4);
Lcd_out(2,1,message2);
for(i = 0; i < 256; i += 250)
{
PWM1_Set_Duty(i);
Delay_ms(200);
}
for(i = 250; i >= 0; i -= 250)
{
PWM1_Set_Duty(i);
Delay_ms(200);
}
}
else if (eeprom_read(0) == 0x02) // Mode 3
{
Lcd_out(1,1,message4);
Lcd_out(2,1,message3);
for(i = 0; i < 256; i += 5)
{
PWM1_Set_Duty(i);
Delay_ms(140);
}
for(i = 253; i >= 0; i -= 5)
{
PWM1_Set_Duty(i);
Delay_ms(120);
}
}
else if (eeprom_read(0) == 0x03) // Mode 4
{
PORTB.F1 = 1;
delay_ms(500);
PORTB.F1 = 0;
delay_ms(500);
}
else // Default mode1
{
Lcd_out(1,1,message4);
Lcd_out(2,1,message1);
mode1 = 0x00;
for(i = 0; i < 256; i += 250)
{
PWM1_Set_Duty(i);
Delay_ms(1000);
}
for(i = 250; i >= 0; i -= 250)
{
PWM1_Set_Duty(i);
Delay_ms(1000);
}
}
}
}
void interrupt() // ISR
{
INTCON.INTF=0;
// mode1 +1;
modecount = 0x01;
mode1 = mode1 + modecount;
eeprom_write(0,mode1);
//goto Loop;
// asm
// {
// reset;
// }
delay_ms(50);
}
Last edited by a moderator: