cần giúp phím nhấn và led đơn trên pic12f629

tanphappc

Học sinh phổ thông
#41
Mã:
#include <12F629.h>
#fuses NOMCLR, INTRC_IO,NOWDT,NOPROTECT, NOPUT, NOPROTECT, NOBROWNOUT, NOCPD
#use delay (clock=4000000)
int8 bien_led,bien=0,over_5s=0;
#define sw  PIN_A3                             
#define led_1 PIN_A0 
#define led_2 PIN_A1
#define led_3 PIN_A2
#int_timer1
void timer_1()
  {
bien++;
if(bien==100)
{
bien=0;if(bien_led!=0)
over_5s=0xaa;
set_timer1(0x3CAF);
}}
void main()
{
SET_TRIS_A(0b00001000);
output_A(0xff);
bien_led=0;
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_1 );
set_timer1(0x3CAF);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
while(1){
if(!input(sw))delay_ms(10);
if(!input(sw)){
if(over_5s==0xaa){bien_led=0;goto thoat;}
bien_led++;if(bien_led>3)bien_led=1;
thoat:
switch ( bien_led){
case 1:
      {
        output_high(led_1);delay_ms(150);
        output_low(led_1);delay_ms(750);
        output_high(led_1);delay_ms(150);
        output_low(led_1);delay_ms(750);
        output_high(led_1);delay_ms(150);
        output_low(led_1);delay_ms(750);
         break;
      }
case 2:
      {
        output_high(led_2);delay_ms(150);
        output_low(led_2);delay_ms(200);
        output_high(led_2);delay_ms(150);
        output_low(led_2);delay_ms(750);
        output_high(led_2);delay_ms(150);
        output_low(led_2);delay_ms(200);
        output_high(led_2);delay_ms(150);
        output_low(led_2);delay_ms(750);
        output_high(led_2);delay_ms(150);
        output_low(led_2);delay_ms(200);
        output_high(led_2);delay_ms(150);
        output_low(led_2);delay_ms(750);
        break;
      }
case 3:
      {
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(200);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(200);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(750);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(200);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(200);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(750);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(200);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(200);
        output_high(led_3);delay_ms(150);
        output_low(led_3);delay_ms(750);
        break;
      }
}
while(!input(sw)){}
delay_ms(10);over_5s=0;bien=0;
}}}
 

tanphappc

Học sinh phổ thông
#42
post: 237183, member: 66006"]
Mã:
#include <12F629 NOPUT, NOPROTECT, NOBROWNOUT, NOCPD
#use delay (clock=4000000
 

Quảng cáo Google