uzzalpic
Junior Member level 2
- Joined
- Mar 24, 2014
- Messages
- 24
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Activity points
- 189
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
sbit sw at GP3_bit;
sbit led_g at GP4_bit;
sbit led_y at GP5_bit;
void main() {
GPIO = 0x0;
TRISIO = 0x8;
do {
if (sw == 0) {
led_g = 0;
led_y = 1;
delay_ms(10000); // 10 second delay
led_y = 0;
led_g = 1;
}
while (sw == 0);
led_y = 0;
led_g = 1;
delay_ms(3000); // 3 second delay
led_g = 0;
led_y = 1;
while(sw==1);
} while (1);
}
It will be when I press switch yellow led will blinking for 10 sec
I used mikroc compiler but here is the code problem with me. i dont know which code use for this circuit.
#define Delay_SWITCH GP3_bit
#define LED_Green GP4_bit
#define LED_Yellow GP5_bit
#define PRESSED 0
#define UNPRESSED 1
void main()
{
CMCON = 0x07;
ANSEL = 0b000000;
GPIO = 0b001001;
TRISIO = 0b001001;
if (Delay_SWITCH == PRESSED)
{
LED_Yellow = 1;
LED_Green = 0;
delay_ms(10000); // 10 sec delay
LED_Yellow = 0;
LED_Green = 1;
}
else if (Delay_SWITCH == UNPRESSED)
{
LED_Yellow = 1;
LED_Green = 0;
delay_ms(180000); // 3 min delay
LED_Yellow = 0;
LED_Green = 1;
}
while(0);
}
Instead of a 3 min delay, have a short blink sequence and repeat it in a for loop to get 3 min.
It surely is no challenge for you:can you give me that code .
can you give me that code .
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 #define ON 1 #define OFF 0 sbit SW at GP3_bit; sbit Yellow_Led at GP5_bit; sbit Green_Led at GP4_bit; unsigned char ten_seconds_delay_count = 20; unsigned int three_minutes_delay_count = 360; unsigned int counter = 0, blink_counter = 0; char myFlags = 0; sbit led_flag at myFlags.B0; sbit button_state at myFlags.B1; //Timer1 //Prescaler 1:8; TMR1 Preload = 3036; Actual Interrupt Time : 500 ms //Place/Copy this part in declaration section void InitTimer1() { T1CON = 0x31; TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; TMR1IE_bit = 1; } void Interrupt() { if((TMR1IE_bit) && (TMR1IF_bit)) { //Enter your code here if(led_flag == 0) { if(++blink_counter == 2) { blink_counter = 0; Yellow_Led = ~Yellow_Led; } if(++counter == ten_seconds_delay_count) { counter = 0; Green_Led = ON; TMR1ON_bit = 0; } } else if(led_flag == 1) { if(++blink_counter == 2) { blink_counter = 0; Yellow_Led = ~Yellow_Led; } if(++counter == three_minutes_delay_count) { counter = 0; Green_Led = ON; TMR1ON_bit = 0; } } TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; } } void Turn_Off_Leds_And_Reset_Counters() { Yellow_Led = OFF; Green_Led = OFF; counter = 0; blink_counter = 0; } void Enable_Interrupts() { INTCON = 0xC0; } void main() { OSCCAL = 0x00; CMCON = 0x07; ANSEL = 0x00; TRISIO = 0x08; GPIO = 0x00; InitTimer1(); button_state = 1; while(1) { if((!SW) && (!button_state)){ Turn_Off_Leds_And_Reset_Counters(); led_flag = 0; Enable_Interrupts(); button_state = 1; } else if((SW) && (button_state)) { Turn_Off_Leds_And_Reset_Counters(); led_flag = 1; Enable_Interrupts(); button_state = 0; } } }
8-pin processor without internal oscillator, good joke.The problem with your code is you have not configured the oscillator. As you are using Internal Oscillator you have to configure OSCCON and OSCTUNE regsiters.
It seems the device doesn't have internal oscillator. So, you have to change the LED pins and use external crystal.
Try this code. The code is developed using mikroC pro compiler.
Code:sbit sw at GP3_bit; sbit led_g at GP4_bit; sbit led_y at GP5_bit; void main() { GPIO = 0x0; TRISIO = 0x8; do { if (sw == 0) { led_g = 0; led_y = 1; delay_ms(10000); // 10 second delay led_y = 0; led_g = 1; } while (sw == 0); led_y = 0; led_g = 1; delay_ms(3000); // 3 second delay led_g = 0; led_y = 1; while(sw==1); } while (1); }
sbit sw at GP3_bit;
sbit led_g at GP4_bit;
sbit led_y at GP5_bit;
void main() {
GPIO = 0x0;
TRISIO = 0x8;
do {
if (sw == 0) {
led_g = 0;
led_y = 1;
delay_ms(10000); // 10 second delay
led_y = 0;
led_g = 1;
}
while (sw == 0);
led_y = 1;
led_g = 0;
delay_ms(180000); // 3 min delay
led_y = 0;
led_g = 1;
while(sw==1);
} while (1);
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 #define ON 1 #define OFF 0 sbit SW at GP3_bit; sbit Yellow_Led at GP5_bit; sbit Green_Led at GP4_bit; unsigned char ten_seconds_delay_count = 20; unsigned int three_minutes_delay_count = 360; unsigned int counter = 0, blink_counter = 0; unsigned char myFlags = 0; sbit led_flag at myFlags.B0; sbit button_state at myFlags.B1; //Timer1 //Prescaler 1:8; TMR1 Preload = 3036; Actual Interrupt Time : 500 ms //Place/Copy this part in declaration section void InitTimer1() { T1CON = 0x31; TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; INTCON = 0xC0; } void Interrupt() { if((TMR1IE_bit) && (TMR1IF_bit)) { //Enter your code here if(led_flag == 0) { if(++blink_counter == 2) { blink_counter = 0; Yellow_Led = ~Yellow_Led; } if(++counter == ten_seconds_delay_count) { counter = 0; Green_Led = ON; TMR1ON_bit = 0; } } else if(led_flag == 1) { if(++blink_counter == 2) { blink_counter = 0; Yellow_Led = ~Yellow_Led; } if(++counter == three_minutes_delay_count) { counter = 0; Green_Led = ON; TMR1ON_bit = 0; } } TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; } } void Turn_Off_Leds_And_Reset_Counters() { Yellow_Led = OFF; Green_Led = OFF; counter = 0; blink_counter = 0; } void Enable_Timer1_Interrupts() { TMR1IE_bit = 1; } void main() { CMCON = 0x07; ANSEL = 0x00; TRISIO = 0x08; GPIO = 0x00; InitTimer1(); button_state = 1; while(1) { if((!SW) && (!button_state)){ Delay_ms(50); if((!SW) && (!button_state)){ Turn_Off_Leds_And_Reset_Counters(); led_flag = 0; Enable_Timer1_Interrupts(); button_state = 1; } } else if((SW) && (button_state)) { Delay_ms(50); if((SW) && (button_state)){ Turn_Off_Leds_And_Reset_Counters(); led_flag = 1; Enable_Timer1_Interrupts(); button_state = 0; } } } }