找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2355|回复: 0
收起左侧

PIC16F877A单片机eeprom 24C04A程序

[复制链接]
ID:962554 发表于 2021-8-27 00:23 | 显示全部楼层 |阅读模式
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51hei.gif
51hei.png

单片机源程序如下:
  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. }
复制代码
51hei.png

所有资料51hei附件下载:
EEPROM_24C64.X.rar (163.73 KB, 下载次数: 53)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表