|
60黑币
用串口调试助手,将数据通过UART下发到单片机当中, 并且存储到EEPROM中, 然后将电源关掉, 重新上电读取EEPROM的数据并数码管上显示出来,但是我现在数据发送单片机也接收了,就是无法存储到EEPROM中,望各位朋友帮忙指点一下,谢谢!
以下是单片机代码:
-----------------------------------------------------------------------------------------------------
- #include <reg52.h>
- #include <intrins.h>
- sbit I2C_SCL = P0^6;
- sbit I2C_SDA = P0^7;
- #define I2CDelay() {_nop_();_nop_();_nop_();_nop_();}
- /* 595控制数码管时钟信号线引脚定义 */
- sbit HC595CLK = P1^1;
- /* 595控制数码管片选信号线引脚定义 */
- sbit HC595RCK = P1^0;
- /* 595控制数码管数据输入引脚定义 */
- sbit HC595DATA = P1^4;
- unsigned char ucDataOneTab[10] = {0x3f,0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f,0x6f};
- unsigned char ucDataTwoTab[8] = {0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F};
- unsigned char led_buf[8] = {0x3f,0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07};
- unsigned char RxdByte = 0;
- void send_dat(unsigned char uiDataOne,unsigned int uiDataTwo)
- {
- unsigned char i;
-
- HC595RCK = 0;
- for(i=0; i<8; i++)
- {
- HC595CLK = 0;
- if(0 != (uiDataOne&0x80))
- {
- HC595DATA = 1;
- }
- else
- {
- HC595DATA = 0;
- }
- uiDataOne <<= 1;
- HC595CLK = 1;
- }
- for(i=0; i<8; i++)
- {
- HC595CLK = 0;
- if(0 != (uiDataTwo&0x80))
- {
- HC595DATA = 1;
- }
- else
- {
- HC595DATA = 0;
- }
- uiDataTwo <<= 1;
- HC595CLK = 1;
- }
- HC595RCK = 1;
- }
- void Delay1ms(int i)
- {
- int j;
- for(; i > 0; i--)
- {
- for(j = 0; j < 110; j++);
- }
- }
- /* 串口配置函数,baud-通信波特率 */
- void ConfigUART(unsigned int baud)
- {
- SCON = 0x50; //配置串口为模式1
- TMOD &= 0x0F; //清零T1的控制位
- TMOD |= 0x20; //配置T1为模式2
- TH1 = 256 - (11059200/12/32)/baud; //计算T1重载值
- TL1 = TH1; //初值等于重载值
- ET1 = 0; //禁止T1中断
- ES = 1; //使能串口中断
- TR1 = 1; //启动T1
- }
- void main()
- {
- unsigned char dat,i;
- unsigned char str[5];
-
- EA = 1;
- ConfigUART(9600);
-
- RxdByte = E2ReadByte(0x02);
- str[0] = (RxdByte/100); //转换为十进制字符串格式
- str[1] = (RxdByte/10%10);
- str[2] = (RxdByte%10);
-
- dat++; //将其数值+1
- //E2WriteByte(0x02, dat); //再写回到对应的地址上
- E2WriteByte(0x02, RxdByte); //再写回到对应的地址上
-
- led_buf[2] = ucDataOneTab[str[2]];
- led_buf[1] = ucDataOneTab[str[1]];
- led_buf[0] = ucDataOneTab[str[0]];
-
- while(1)
- {
- for(i=0; i<8; i++)
- {
- send_dat(led_buf[i],ucDataTwoTab[i]);
- Delay1ms(1);
- }
- }
- }
- void InterruptUart() interrupt 4
- {
- if(RI)
- {
- RI = 0;
- RxdByte = SBUF;
- SBUF = RxdByte + 1;
- }
- if(TI)
- {
- TI = 0;
- }
- }
复制代码
---------------------------------------------------------------------------------------------------------------
|
|