/* Main.c file generated by New Project wizard
*
* Created: Tuesday April 10, 2018
* Processor: PIC18F452
* Compiler: MPLAB C18
*/
#include #define RW PORTBbits.RB5 #define RS PORTBbits.RB6 #define EN PORTBbits.RB7 #define P0 PORTD #define ADGO ADCON0bits.GO void tmr(void); void KeyInterrupt1 (void); //Interrupt service function void KeyInterrupt2 (void); //Interrupt service function void KeyInterrupt3 (void); //Interrupt service function void lcd_show(void); void lcd_show1(void); void lcd_show2(void); void lcd_show3(void); void lcd_show4(void); void lcd_show5(void); void lcd_show6(void); unsigned int AD_Trs(void); unsigned int AD_Trs1(void); unsigned int AD_Trs2(void); //int j=0; //int time=0; //int timem=0; int intermode=0; unsigned int lednum=0; int max=4000,max1=3900,max2=3800,max3=3700; int min=1000,min1=900,min2=800,min3=1000; unsigned char time2[7]="wangkuod"; unsigned int a1=0,a2=0,a3=0; int init(); //Declare initialization function int write_com(unsigned char); //declare write command function int write_date(unsigned char); //declare the write data function int delay(unsigned char); //declare delay function unsigned char x; //sbit RS = P1^0; // sbit RW = P1^1; //sbit EN = P1^2; //unsigned char table[]="HELLO!"; //unsigned char table1[]="2018/4/16"; void main(void) //Main function { TRISD=0; TRISBbits.TRISB0=1; TRISBbits.TRISB1=1; TRISBbits.TRISB2=1; TRISBbits.TRISB5=0; TRISBbits.TRISB6=0; TRISBbits.TRISB7=0; TRISAbits.TRISA0=1; TRISAbits.TRISA1=1; TRISAbits.TRISA2=1; TRISAbits.TRISA6=0; // INTCON |= 0xa0; // Enable global interrupt and Timer0 interrupt //INTCONbits.TMR0IE=1; INTCONbits.GIE=1; //INT0 INTCON2bits.INTEDG0=1; INTCONbits.INT0IF=0; INTCONbits.INT0IE=1; //INT1 INTCON2bits.INTEDG1=1; INTCON3bits.INT1IF=0; INTCON3bits.INT1IE=1; //int2 INTCON2bits.INTEDG2=1; INTCON3bits.INT2IF=0; INTCON3bits.INT2IE=1; //TMR0H = 25536/256; //high 8 bits //TMR0L = 25536%256; //low 8 bits //T0CON = 0x88; //Enable Timer0 and set it as a 16-bit timer without prescaler //AD ADCON0=0x81; //-- ADFM ADCS2 —— —— PCFG3 PCFG2 PCFG1 PCFG0 //-- 1 0 0 0 1 1 1 0 //Right-aligned (the upper 6 bits of the ADRESH register are read as 0), AN0 is the analog input bit, reference positive and negative voltage //VDD and VSS respectively ADCON1 = 0x8e; heat(); // write_com(0x80); // for(x=0;x<6;x++) // { // write_date(table[x]); // delay(150); // } //for(x=0;x<6;x++) // { // write_date(time); // delay(150); // } // write_com(0x80); // for(x=0;x<17;x++) // { // write_date(table1[x]); // delay(150); // } while(1) { unsigned int a; lednum = AD_Trs(); write_com(0x80); time2[1]='0'; lcd_show(); lednum = AD_Trs1(); write_com(0x80+0x08); time2[1]='1'; lcd_show(); lednum = AD_Trs2(); write_com(0x80+0x40); time2[1]='2'; lcd_show(); switch(intermode) { case 0: {write_com(0x80+0x40+0x08); lcd_show1();break; } case 1: {write_com(0x80+0x40+0x08); lcd_show2();break;} case 2: {write_com(0x80+0x40+0x08); lcd_show3();break; } case 3: {write_com(0x80+0x40+0x08); lcd_show4();break; } case 4: {write_com(0x80+0x40+0x08); lcd_show5();break; } case 5: {write_com(0x80+0x40+0x08); lcd_show6();break; } default: {write_com(0x80); lcd_show1();break; } } if(lednum>max1|lednum>max2|lednum>max3|lednum //{PORTAbits.RA3=0; // delay(50); // PORTAbits.RA3=1; // delay(50); // PORTAbits.RA3=0; // delay(50); // PORTAbits.RA3=1; // delay(50);} PORTAbits.RA6=1; } } } #pragma code xx=0x0008 //MCC18 interrupt must be implemented with an assembly line void inter(void) //xx is the priority. If there is no priority, xx can be omitted. { if(INTCONbits.INT0IF){ _asm goto KeyInterrupt1 _endasm} else if(INTCON3bits.INT1IF){ _asm goto KeyInterrupt2 _endasm } else { _asm goto KeyInterrupt3 _endasm } } //=======Interrupt service function========== #pragma interrupt KeyInterrupt1 void KeyInterrupt1 (void) { if (INTCONbits.INT0IF && INTCONbits.INT0IE) //Interrupt flag bit judgment { //T0CONbits.TMR0ON=~T0CONbits.TMR0ON; INTCONbits.INT0IF = 0; // Clear the interrupt flag switch(intermode) { case 0: {max1=max1+100; break; } case 1: {max2=max2+100;break;} case 2: {max3=max2+100;break; } case 3: {min1=min1+100; break; } case 4: {min2=min2+100;break; } case 5: {min3=min3+100;break; } default: {max1=max1+100;break; } } } } #pragma code //=======Interrupt service function========== #pragma interrupt KeyInterrupt2 void KeyInterrupt2 (void) { if (INTCON3bits.INT1IF && INTCON3bits.INT1IE) //Interrupt flag bit judgment { //T0CONbits.TMR0ON=~T0CONbits.TMR0ON; //intermode=~intermode; INTCON3bits.INT1IF = 0; // Clear the interrupt flag intermode++; if(intermode>5) {intermode=0;} } } #pragma code #pragma interrupt KeyInterrupt3 void KeyInterrupt3 (void) { if (INTCON3bits.INT2IF && INTCON3bits.INT2IE) //Interrupt flag bit judgment { //time=timem=j=0; // T0CONbits.TMR0ON=0; INTCON3bits.INT2IF = 0; // Clear the interrupt flag switch(intermode) { case 0: {max1=max1-100; break; } case 1: {max2=max2-100;break;} case 2: {max3=max2-100;break; } case 3: {min1=min1-100; break; } case 4: {min2=min2-100;break; } case 5: {min3=min3-100;break; } default: {max1=max1-100;break; } } } } #pragma code int init() // Initialization function body { EN = 0; write_com(0X38); //Set 16*2 display, 5*7 dot matrix, 8-bit data interface write_com(0X0C); //Set to display, do not display cursor write_com(0X06); //When writing a character, the entire screen moves right write_com(0X01); //display clear return 0; } int write_com(unsigned char com) // write command function body { RS = 0; RW = 0; P0 = com; delay(5); EN = 1; delay(5); EN = 0; return 0; } int write_date(unsigned char date) // Function body for writing data { RS = 1; RW = 0; P0 = date; delay(5); EN = 1; delay(5); EN = 0; return 0; } int delay(unsigned char xms) { unsigned char x,y; for(x=xms;x>0;x--) for(y=110;y>0;y--); return 0; } void lcd_show1(void) { // unsigned char a,b; // unsigned char time2[7]; // unsigned int time1[2]; // unsigned int time3[2]; //time3[0]=j/10; //time3[1]=j%10; //time1[0]=time/10; //time1[1]=time%10; //This algorithm is used to extract the individual bits of an integer to display on the LCD a1 = max1/1000; a2 = max1%1000/100; a3 = max1%100/10; //a4 = lednum%10; time2[0]='A'; time2[1]='0'; time2[2]='M'; time2[3]='0'+a1; time2[4]='.'; time2[5]='0'+a2; time2[6]='0'+a3; for(x=0;x<7;x++) { write_date(time2[x]); delay(15); } } void lcd_show2(void) { // unsigned char a,b; // unsigned int time1[2]; // unsigned int time3[2]; // unsigned int a1=0,a2=0,a3=0; //time3[0]=j/10; //time3[1]=j%10; //time1[0]=time/10; //time1[1]=time%10; //This algorithm is used to extract the individual bits of an integer to display on the LCD a1 = max2/1000; a2 = max2%1000/100; a3 = max2%100/10; //a4 = lednum%10; time2[0]='A'; time2[1]='1'; time2[2]='M'; time2[3]='0'+a1; time2[4]='.'; time2[5]='0'+a2; time2[6]='0'+a3; for(x=0;x<7;x++) { write_date(time2[x]); delay(15); } } void lcd_show3(void) { // unsigned char a,b; // unsigned char time2[7]; // unsigned int time1[2]; // unsigned int time3[2]; // unsigned int a1=0,a2=0,a3=0; //time3[0]=j/10; //time3[1]=j%10; //time1[0]=time/10; //time1[1]=time%10; //This algorithm is used to extract the individual bits of an integer to display on the LCD a1 = max3/1000; a2 = max3%1000/100; a3 = max3%100/10; //a4 = lednum%10; time2[0]='A'; time2[1]='2'; time2[2]='M'; time2[3]='0'+a1; time2[4]='.'; time2[5]='0'+a2; time2[6]='0'+a3; for(x=0;x<7;x++) { write_date(time2[x]); delay(15); } } void lcd_show4(void) { // unsigned char a,b; // unsigned char time2[7]; // unsigned int time1[2]; // unsigned int time3[2]; // unsigned int a1=0,a2=0,a3=0; //time3[0]=j/10; //time3[1]=j%10; //time1[0]=time/10; //time1[1]=time%10; //This algorithm is used to extract the individual bits of an integer to display on the LCD a1 = min1/1000; a2 = min1%1000/100; a3 = min1%100/10; //a4 = lednum%10; time2[0]='A'; time2[1]='0'; time2[2]='m'; time2[3]='0'+a1; time2[4]='.'; time2[5]='0'+a2; time2[6]='0'+a3; for(x=0;x<7;x++) { write_date(time2[x]); delay(15); } } void lcd_show5(void) { // unsigned char a,b; // unsigned char time2[7]; // unsigned int time1[2]; // unsigned int time3[2]; // unsigned int a1=0,a2=0,a3=0; //time3[0]=j/10; //time3[1]=j%10; //time1[0]=time/10; //time1[1]=time%10; //This algorithm is used to extract the individual bits of an integer to display on the LCD a1 = min2/1000; a2 = min2%1000/100; a3 = min2%100/10; //a4 = lednum%10; time2[0]='A'; time2[1]='1'; time2[2]='m'; time2[3]='0'+a1; time2[4]='.'; time2[5]='0'+a2; time2[6]='0'+a3; for(x=0;x<7;x++) { write_date(time2[x]); delay(15); } } void lcd_show6(void) { // unsigned char a,b; // unsigned char time2[7]; // unsigned int time1[2]; // unsigned int time3[2]; // unsigned int a1=0,a2=0,a3=0; //time3[0]=j/10; //time3[1]=j%10; //time1[0]=time/10; //time1[1]=time%10; //This algorithm is used to extract the individual bits of an integer to display on the LCD a1 = min3/1000; a2 = min3%1000/100; a3 = min3%100/10; //a4 = lednum%10; time2[0]='A'; time2[1]='2'; time2[2]='m'; time2[3]='0'+a1; time2[4]='.'; time2[5]='0'+a2; time2[6]='0'+a3;
Previous article:PIC microcontroller drives LCD12864 to display characters source code
Next article:Proteus simulation and source program of laser communication based on PPM modulation of PIC16F877A microcontroller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- EEWORLD University ---- Working Principle of Diode
- How do you know what power dissipation you need to choose for a diode in a circuit?
- Intel FPGA 2019 Engineer Application Video
- AD drawing PCB has many white lines after enlarging
- AD Ignore DRC with irregular slotting settings using pad stacking
- High frequency characteristics of resistors
- Problems with dynamic load line locus of transistor switches
- Inductor ripple rate r value selection problem
- BOX unpacking test
- EEWORLD University Hall--Understand the development history of smart home in one minute (video)