仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- /*
- * File: newmain.c
- * Author: SDS
- *
- * Created on 29 December, 2019, 11:59 AM
- */
- // PIC16F877A Configuration Bit Settings
- // 'C' source line config statements
- // CONFIG
- #pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
- #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
- #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
- #pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
- #pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
- #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
- #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
- #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
- // #pragma config statements should precede project file includes.
- // Use project enums instead of #define for ON and OFF.
- #define _XTAL_FREQ 20000000
- #include <xc.h>
- #include <stdio.h>
- //#include <stdlib.h>
- #include <stdint.h>
- #include "LCD.h"
- #include "I2C.h"
- #include "EEPROM.h"
- #include "ADC.h"
- char lcd[20];
- void main()
- {
- TRISD=0;
- LCD_init();
- I2C_Init(400);
- Init_ADC();
- LCD_command(clear);
- Lcd_string(1,1,"<-- WELCOME -->");
- __delay_ms(200); LCD_command(clear);
- unsigned int ADC_value = 0;
- unsigned int ADC_value1 = 0;
- unsigned int i=0;
- unsigned char rx,rx1,rx2,rx4=0;
- uint16_t rx3;
- // Write_Byte_To_EEPROM(0x0000,'S');
- // Write_Byte_To_EEPROM(0x0001,'D');
- // Write_Byte_To_EEPROM(0x0002,'S');
- // Write_Byte_To_EEPROM(0x0003,i);
- while(1)
- {
- ADC_value = ADCValue(6);
- ADC_value1 = ADCValue(5);
- rx4=Read_Byte_From_EEPROM(0004);
- rx2=Read_Byte_From_EEPROM(0005);
- rx3=((rx4<<8)|rx2);
- sprintf(lcd,"MEM:%3u",rx3);Lcd_string(1,1,lcd);
- sprintf(lcd,"ADC:%3u",ADC_value);Lcd_string(2,1,lcd);
- sprintf(lcd,"ADC:%3u",ADC_value1);Lcd_string(4,1,lcd);
- // __delay_ms(50);
- if(ADC_value>1000)
- {
- Write_Byte_To_EEPROM(0004,ADC_value1>>8);
- Write_Byte_To_EEPROM(0005,ADC_value1);
- }
- if(i>100){i=0;}i++;
- sprintf(lcd,"I:%3u",i);Lcd_string(3,1,lcd);
-
- ///////////////////////// END /////////////////////////////
- }
- }
复制代码
所有资料51hei附件下载:
EEPROM_24C64.X.rar
(163.73 KB, 下载次数: 57)
|