⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 first.c

📁 Pulse generator Using CCS and PIC16F628
💻 C
字号:
#include <16F628.h>
#fuses INTRC_IO, NOLVP, NOWDT, PUT, NOBROWNOUT,NOMCLR,PROTECT
#use delay(clock=4000000)


#define S0  PIN_A0
#define S1  PIN_A1
#define S2  PIN_A2
#define S3  PIN_A3
#define S4  PIN_A4
#define S5  PIN_A5
#define S6  PIN_A6
//#define S7  PIN_A7
#define OUT PIN_A7

#define B0  PIN_B0
#define B1  PIN_B1
#define B2  PIN_B2
#define B3  PIN_B3
#define B4  PIN_B4
#define B5  PIN_B5
#define B6  PIN_B6

int const ligado=10;
int const intervalo=10;
int const desligado=20;


void pulsos (int x) {
      int i=0;
   output_high(S6);
   for (i=0;i<x;i++){ 
              
  
                  delay_ms(intervalo);
					   output_low(OUT);
			         delay_ms(desligado);
			         output_high(OUT);
		            delay_ms(ligado);
      
   } 
     delay_ms(20);
     output_low(OUT);
     output_low(S6);
}

void main ( void ) {

      disable_interrupts(GLOBAL);                  // all interrupts OFF
      set_tris_a(0b00000000);                      // todas como saidas
      set_tris_b(0b11111110);                      // todas como entradas

      output_a(0x00);

      while (TRUE) {
                  output_low(S0);
			         output_high(S0);

            if ( input( B1 ) ) {
                while ( input( B1 ) ) {                 // ESPERA SOLTAR

                }
                  pulsos( 1 );
                  delay_us(1000);                                
             }


               if ( input( B2 ) ) {
                while ( input( B2 ) ) {                 // ESPERA SOLTAR

                }
                  pulsos( 5 );
                  delay_us(1000);                                
             }

            if ( input( B3 ) ) {
                while ( input( B3 ) ) {                 // ESPERA SOLTAR

                }
                  pulsos( 10 );
                  delay_us(1000);                                
             }

            if ( input( B4 ) ) {
                while ( input( B4 ) ) {                 // ESPERA SOLTAR

                }
                  pulsos( 50 );
                  delay_us(1000);                                
             }






                  
            
       }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -