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

📄 f_11_8_pottst.c

📁 PIC_Hi-Tech_C_Mike_Pearces_I2C_routines Microchi PIC_Hi-Tech C_I2C_for_EEPROM_24LC01B Code
💻 C
字号:
#include "config.h"#include "serial.c"#include "serio.c"void spi_setpotmtr(unsigned char c); #define POTCS 4  //RB4 is select for potentiometervoid spi_setpotmtr(unsigned char c){  bitclr(PORTB, POTCS);  // select potmtr  SSPBUF = 0x11; // write command  while(!SSPIF); // wait until transmitted  SSPIF = 0;     // reset  SSPBUF = c;    // write data  while(!SSPIF); // wait until transmitted  SSPIF = 0;     // reset  bitset(PORTB, POTCS);  // deselect potmtr}#if defined(__18CXX)void my_gets (char *s);//return a string from the consolevoid my_gets (char *s){ char c;  do {  c = getche();  *s = c;  s++;  } while (c != '\r');}#endifvoid main(void){  unsigned char pv;  // set select line for output  bitclr(TRISB,POTCS);  bitset(PORTB, POTCS);  // deselect pot  serial_init(95,1); // 19200 in HSPLL mode, crystal = 7.3728 MHz  // configure SPI port for potentiometer  CKE = 1; // data transmitted rising edge of SCK  CKP = 0; // clk idle is low  bitclr(TRISC,3);  //SCK, output  bitclr(TRISC,5);  // SDO, output  bitset(TRISC,4);  // SDI pin is input, unused  // SPI Master Mode FOSC/16  SSPM3 = 0;  SSPM2 = 0; SSPM1 = 0;  SSPM0 = 1;  SSPEN = 0; // reset Sync Serial port  SSPEN = 1; // enable Sync Serial port  SSPIF = 0;  // clear SPIF bit  pcrlf();  printf("Potentiometer test started");  pcrlf();  while(1) {    printf("Input value (0-255): ");#if defined(HI_TECH_C)	    scanf("%d", &pv);#endif#if defined(__18CXX)    {// MCC18 does not have scanf, just get string from console, use atoi	  char buf[30];	  my_gets(buf);  // get a string from console	  pv = atoi(buf);  // convert string to integer	}#endif    pcrlf();    printf("Sending %d to pot.",pv);    pcrlf();    spi_setpotmtr(pv);  }}

⌨️ 快捷键说明

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