f_8_18a_ledsw_a.c

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

C
34
字号
#include "config.h"#include "serial.c"#include "serio.c"#include "delay.h"// this code illustrates a WRONG 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. What will happen is that loop is // exited on first press, as variable i is incremented// while switch is held down. 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    if (!RB6) {      i++;      // wrong -- will increment while switch is pressed    }  }  printf("loop exited, i value is: %d\n",i); pcrlf();  while(1);  // loop forever}

⌨️ 快捷键说明

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