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

📄 lcd2demo_85j90_r0.c

📁 是关于PIC单片机(型号是PIC18f85j90)实现液晶显示的一个DEMO
💻 C
📖 第 1 页 / 共 3 页
字号:
/***********************************************************************
 *
 * PICDEM LCD2 Demo Program for 85J90 family devices.
 *
 ***********************************************************************
 * FileName:            LCD2Demo_85J90_R0.C
 * Dependencies:		LCD_85J90.h
 * Processor:           PIC18F85J90
 * Assembler:
 * Linker:
 * Compiler:			C18
 * Company:             Microchip Technology, Inc.
 *
 * Microchip Technology Incorporated ("Microchip") retains all ownership
 * and intellectual property rights in the code accompanying this message
 * and in all derivatives hereto.  You may use this code, and any
 * derivatives created by any person or entity by or on your behalf,
 * exclusively with Microchip抯 proprietary products.  Your acceptance
 * and/or use of this code constitutes agreement to the terms and
 * conditions of this notice.
 *
 * CODE ACCOMPANYING THIS MESSAGE IS SUPPLIED BY MICROCHIP "AS IS".
 * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING,
 * BUT NOT LIMITED TO, IMPLIED WARRANTIES OF NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS CODE,
 * ITS INTERACTION WITH MICROCHIP扴 PRODUCTS, COMBINATION WITH ANY OTHER
 * PRODUCTS, OR USE IN ANY APPLICATION.
 *
 * YOU ACKNOWLEDGE AND AGREE THAT, IN NO EVENT, SHALL MICROCHIP BE
 * LIABLE, WHETHER IN CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE OR
 * BREACH OF STATUTORY DUTY), STRICT LIABILITY, INDEMNITY, CONTRIBUTION,
 * OR OTHERWISE, FOR ANY INDIRECT, SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL
 * OR CONSEQUENTIAL LOSS, DAMAGE, FOR COST OR EXPENSE OF ANY KIND WHATSOEVER
 * RELATED TO THE CODE, HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED
 * OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
 * ALLOWABLE BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
 * RELATED TO THIS CODE, SHALL NOT EXCEED THE PRICE YOU PAID DIRECTLY TO
 * MICROCHIP SPECIFICALLY TO HAVE THIS CODE DEVELOPED.
 *
 * You agree that you are solely responsible for testing the code and
 * determining its suitability.  Microchip has no obligation to modify,
 * test, certify, or support the code.
 *
 * Refer to the PICDEM LCD 2 Users Guide.
 **********************************************************************/
#include "p18f85j90.h"
#include "LCD_85J90.h"

//***********************************************************************
// Configuration bits
//***********************************************************************
#pragma config DEBUG  = OFF
#pragma config XINST  = OFF
#pragma config STVREN = OFF
#pragma config WDTEN  = OFF
#pragma config CP0    = OFF
#pragma config IESO   = OFF
#pragma config FCMEN  = OFF
#pragma config FOSC2  = OFF
#pragma config FOSC   = HS
#pragma config WDTPS  = 256
#pragma config CCP2MX = DEFAULT

//**********************************************************************
// Function Prototypes
//**********************************************************************
void LCD_CONFIG_CP (void);
void LCD_CONFIG_R (void);
void DisplayOn (void);
void DisplayOff (void);
void BarGraph (unsigned char);
void CirGraph (unsigned char);
void S1Num (unsigned char);
void S2Num (unsigned char);
void S3Num (unsigned char);
void S4Num (unsigned char);
void S5Num (unsigned char);
void S6Num (unsigned char);
void S7Num (unsigned char);
void S8Num (unsigned char);
void LLine (unsigned int);
void ULine (unsigned short long);

void Voltmeter (void);
void VoltM_Display (unsigned short long i);
void BttryIndic (unsigned char i);

void Thermometer (void);
void Temp_Display_C (unsigned short long i);
void Temp_Display_F (unsigned short long i);
void TempIndic (unsigned char i);

void RTC_Display(void);
void InitialDemo(void);

unsigned short long HEX2BIN (unsigned int);
unsigned short long AdjustBCD (unsigned short long);

void InterruptHandlerHigh (void);

void Delay3 (void);
void Delay_LP (void);
void Delay_LP1 (void);
//**********************************************************************
// Defines
//**********************************************************************
#define A 10
#define C 12
#define E 14
#define F 15
#define H 17
#define L 21
#define P 25



#define F_1 1
#define F_2 2
#define F_3 3
#define F_4 4
#define EnableAll 0xFF
#define No_Disp 255

#define Pressed 0
#define Default 1
#define SW3 	PORTAbits.RA6
#define SW4 	PORTAbits.RA7

//**********************************************************************
// Structure Definitions
//**********************************************************************
typedef union
 {
  struct
  {
  unsigned b0:1;
  unsigned b1:1;
  unsigned b2:1;
  unsigned b3:1;
  unsigned b4:1;
  unsigned b5:1;
  unsigned b6:1;
  unsigned b7:1;
  }location;
  unsigned char ch;
 }Bytebits;

struct INT_nibble {
				unsigned a: 4;
				unsigned b: 4;
				unsigned c: 4;
				unsigned d: 4;
};

struct S_LONG_nibble {
				unsigned a: 4;
				unsigned b: 4;
				unsigned c: 4;
				unsigned d: 4;
				unsigned e: 4;
				unsigned f: 4;
};

union integer {
				struct INT_nibble Nib;
				unsigned char Char;
				unsigned int  Int;
};

union SL {
				  struct S_LONG_nibble Nib;
				  unsigned short long S_Long;
};
//**********************************************************************
// Variable declaration
//**********************************************************************

unsigned char i, cnt, Temp;
unsigned int j;
unsigned short long k;

struct INT_nibble Vn;
union integer In;

struct S_LONG_nibble ST_Ln;
union SL BCD;

unsigned int an0voltage, an2voltage;
unsigned int Reading;

unsigned char BD_VLTG_x10_InHex;

unsigned char SEC, MIN, HR;

unsigned char BGCNT, SEC_FLAG, SEC_FG, TMR3FG, TMP_CNT;

unsigned char DemoCode, S_2, S_1, BiasBits;

unsigned char i0,i1,i2;
Bytebits Port_bits, Temp_bits;
//**********************************************************************
// Main Program
//**********************************************************************

void main (void)
{
    OSCCON  = 0b01000000;  //1 MHZ
    OSCTUNE = 0b01100000;

	BD_VLTG_x10_InHex = 0x21; // 0x21 for 3.3 V  0x32 for 5V.
	BGCNT = 0;
	SEC_FLAG = 0;

	TRISBbits.TRISB0 = 0; 	// Control Power for RS-232, Thermistor, Voltmeter & EEPROM

	INTCONbits.RBIE = 1;
	INTCONbits.GIE  = 1;
	INTCONbits.PEIE = 1;

	LCD_CONFIG_CP(); 		// Configure LCD module to use internal Charge Pump.
	LATBbits.LATB0 = 0;   	// Power OFF for AUX.
	DisplayOn();
	Delay3();
	DisplayOff();
	MCHPON; VaritronixON; 	// Display MCHP & Varitronix Symbol.

	WDTCONbits.REGSLP = 1; 	// Configure Voltage Regulator to enter Stand by mode.
	Sleep(); 				// Low Power Mode.

	S_1 = Default;
	S_2 = Default;
	while (S_2 == Default)
	{
	   S1Num(H);S2Num(E);S3Num(L);S4Num(L);S5Num(0);
 	   DemoCode = F_1;
	}

	DisplayOff();

	//Timer1 Initialization
	TMR1H = 0x80;
	T1CONbits.T1RUN = 1;
	T1CONbits.T1CKPS0 = 0;
	T1CONbits.T1OSCEN = 1;
	T1CONbits.T1SYNC = 1;
	T1CONbits.TMR1CS = 1;
	T1CONbits.TMR1ON = 1;
	PIE1bits.TMR1IE = 0;

	while(1)
	{

		while (DemoCode == F_1)
		{
			ADCON1 = 0x0C;			//RA0-RA2 Analog inputs.
			S_1 = Default;
			S_2 = Default;
		 	F1ON; MCHPON; VaritronixON;
			LATBbits.LATB0 = 1;   	// Power ON Needed for this test.
			TRISAbits.TRISA0 = 1; 	//AN0
			ADCON0bits.CHS3 = 0;  	// channel 0
			ADCON0bits.CHS2 = 0;
			ADCON0bits.CHS1 = 0;
			ADCON0bits.CHS0 = 0;
			ADCON2 = 0xBF;		  	// right justify, A/D RC Osc
			ADCON0bits.ADON = 1;  	// ADC on


			while (S_2 == Default)
			{
				PIR1bits.ADIF = 0;
				PIE1bits.ADIE = 1;
				ADCON0bits.GO_DONE = 1;
				Sleep();
				Reading = an0voltage;
				Voltmeter();
			}

			DemoCode = F_2;
			DisplayOff();
			ADCON0bits.ADON = 0;  	// ADC Off
		}
		while (DemoCode == F_2)
		{
			S_1 = Default;
			S_2 = Default;
			F2ON; MCHPON; VaritronixON;
			TRISAbits.TRISA2 = 1; 	//AN2
			ADCON0bits.CHS3 = 0;  	// channel 2
			ADCON0bits.CHS2 = 0;
			ADCON0bits.CHS1 = 1;
			ADCON0bits.CHS0 = 0;
			ADCON2 = 0xBF;			// right justify, A/D RC Osc
			ADCON0bits.ADON = 1;	// ADC on
			cnt = 4; //n samples
			SEC_FG = 1;
			TMP_CNT = 2;

			while (S_2 == Default)
			{
				Reading = 0;
				for ( i=0; i<cnt; i++)
				{
					PIR1bits.ADIF = 0;
					PIE1bits.ADIE = 1;
					ADCON0bits.GO_DONE = 1;
					Sleep();
					Reading += an2voltage;
				}
				Reading /= cnt;
				if (SEC_FG == 1) { SEC_FG = 0;TMP_CNT++;}
				if (TMP_CNT == 3)
				{
					TMP_CNT = 0;
					Thermometer();
				}
			}
			DemoCode = F_3;
			DisplayOff();
			ADCON0bits.ADON = 0;  // ADC Off
			LATBbits.LATB0 = 0;   // Power Off for AUX

		}
		while (DemoCode == F_3)
		{
			S_1 = Default;
			S_2 = Default;

			F3ON; MCHPON; VaritronixON;
			PIE1bits.TMR1IE = 1;
			MIN = 0; HR = 0; SEC = 0;

			while (S_2 == Default)
			{
				RTC_Display();
				Sleep();
				if (SW4 == Pressed)
				{
				  while(SW4 == Pressed)
				  {
					  Delay_LP1();	//Delay for Key press
					  if (SW3 == Pressed) MIN++;
					  else if (SW4 == Pressed) HR++;
					  RTC_Display();
				   }
				}
			}
			DemoCode = F_4;
			DisplayOff();
			PIE1bits.TMR1IE = 0;
		}
		while (DemoCode == F_4)
		{
			OSCCONbits.IRCF2 = 0;

⌨️ 快捷键说明

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