picdem2.c

来自「Hitech microchip PIC C18 Compiler」· C语言 代码 · 共 56 行

C
56
字号
/* This is a simple demo project written for use with * the HI-TECH Software PICC18 compiler. It may be compiled * and run on the Microchip PICDEM 2 PLUS DEMO BOARD. * Features demonstrated include driving the LCD display and * the A2D converter.   Additional files required for this demo are included in the PIC18\SAMPLES directories: DELAY\delay.c DELAY\delay.h LCD\lcd.c LCD\lcd.h */#include <pic18.h>#include <stdio.h>#include "lcd.h"/* this is the maximum value of an A2D conversion. */#define MAXVOLTAGE 5void init(void){	lcd_init(FOURBIT_MODE);	ADON=1;	/* enable A2D converter */	ADIE=0;	/* not interrupt driven */	ADCON1=0;	ADCON0=1;}void main(void){	unsigned char last_value;	unsigned char volts;	unsigned char decivolts;	unsigned char outString[20];	init();	lcd_puts("Starting");	while(1){		GODONE=1;		while(GODONE)continue;		ADIF=0;		if(ADRESH!=last_value)		{			volts=0;			for(decivolts=(ADRESH*10*MAXVOLTAGE/255);decivolts>=10;decivolts-=10)				volts++;			lcd_clear();			sprintf(outString,"A2D = %d.%d volts",volts,decivolts);			lcd_puts(outString);		}		last_value=ADRESH;	}}

⌨️ 快捷键说明

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