標(biāo)題: PIC16F877A單片機(jī)eeprom 24C04A程序 [打印本頁]

作者: Sdstechsds    時間: 2021-8-27 00:23
標(biāo)題: PIC16F877A單片機(jī)eeprom 24C04A程序
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)



單片機(jī)源程序如下:
  1. /*
  2. * File:   newmain.c
  3. * Author: SDS
  4. *
  5. * Created on 29 December, 2019, 11:59 AM
  6. */
  7. // PIC16F877A Configuration Bit Settings
  8. // 'C' source line config statements
  9. // CONFIG
  10. #pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
  11. #pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
  12. #pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
  13. #pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
  14. #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)
  15. #pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
  16. #pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
  17. #pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

  18. // #pragma config statements should precede project file includes.
  19. // Use project enums instead of #define for ON and OFF.
  20. #define _XTAL_FREQ 20000000
  21. #include <xc.h>
  22. #include <stdio.h>
  23. //#include <stdlib.h>
  24. #include <stdint.h>
  25. #include "LCD.h"
  26. #include "I2C.h"
  27. #include "EEPROM.h"
  28. #include "ADC.h"

  29. char lcd[20];

  30. void main()
  31. {
  32.     TRISD=0;
  33.     LCD_init();
  34.     I2C_Init(400);
  35.     Init_ADC();
  36.     LCD_command(clear);
  37.     Lcd_string(1,1,"<--   WELCOME   -->");
  38.     __delay_ms(200);  LCD_command(clear);
  39.     unsigned int ADC_value = 0;
  40.     unsigned int ADC_value1 = 0;
  41.     unsigned int i=0;
  42.     unsigned char rx,rx1,rx2,rx4=0;
  43.     uint16_t rx3;
  44.    // Write_Byte_To_EEPROM(0x0000,'S');
  45.    // Write_Byte_To_EEPROM(0x0001,'D');
  46.    // Write_Byte_To_EEPROM(0x0002,'S');
  47.    // Write_Byte_To_EEPROM(0x0003,i);
  48.     while(1)
  49.     {
  50.         ADC_value = ADCValue(6);
  51.         ADC_value1 = ADCValue(5);   
  52.       rx4=Read_Byte_From_EEPROM(0004);
  53.       rx2=Read_Byte_From_EEPROM(0005);
  54.       rx3=((rx4<<8)|rx2);
  55.       sprintf(lcd,"MEM:%3u",rx3);Lcd_string(1,1,lcd);
  56.       sprintf(lcd,"ADC:%3u",ADC_value);Lcd_string(2,1,lcd);
  57.       sprintf(lcd,"ADC:%3u",ADC_value1);Lcd_string(4,1,lcd);
  58.     // __delay_ms(50);
  59.       if(ADC_value>1000)
  60.       {
  61.         Write_Byte_To_EEPROM(0004,ADC_value1>>8);
  62.         Write_Byte_To_EEPROM(0005,ADC_value1);
  63.       }
  64.             if(i>100){i=0;}i++;
  65.             sprintf(lcd,"I:%3u",i);Lcd_string(3,1,lcd);
  66.       
  67. ///////////////////////// END /////////////////////////////
  68.     }
  69. }
復(fù)制代碼


所有資料51hei附件下載:
EEPROM_24C64.X.rar (163.73 KB, 下載次數(shù): 57)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1