f_8_18b_ledsw_b.c

来自「* Use 10 MHz crystal frequency. * Use 」· C语言 代码 · 共 43 行

C
43
字号
#include "config.h"#include "serial.c"#include "serio.c"#include "delay.h"// this code illustrates one RIGHT way to read a switch// for press and release.// Modified from book example so that loop is// exited after 'i' reaches 5, and message// is printed. So loop is not exited until // switch is pressed and relased 5 times.//  void main(void){  int i;  TRISB = 0xEF;		// set RB4 as output    RB4 = 0;		// turn RB4 off  serial_init(95,1);   // 19200 in HSPLL mode, crystal = 7.3728 MHz   pcrlf();printf ("Press switch when ready!");pcrlf();  i = 0;  // illustrates wrong way to read a switch for presses  while(i < 5) {  // exit loop if i >= 5    // wait for press    while(RB6);  //loop (1)    DelayMs(30); //debounce    // wait for release    while (!RB6); //loop (2)    DelayMs(30);   //debounce    i++;  }  printf("loop exited, i value is: %d\n",i); pcrlf();  while(1);  // loop forever}

⌨️ 快捷键说明

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