Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问

*本文及代码参阅彭伟《单片机C语言程序设计实训100例》
一,打开文件(可以随文下载放置在文档中打开)。(如下图1所示)
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第1张图片
图1

二,调整原理图大小,适合可视,另存工程文件。(如下图2,3,4所示)
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第2张图片
图2
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第3张图片
图3
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第4张图片
图4

三,点击Source Code标签。(如下图5所示)
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第5张图片
图5

四,编辑main.c Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问 (如下图6所示)
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第6张图片
图6

五,Main.c 代码:
//-----------------------------------------------------------------
// 名称: Flash程序空间的数据访问
//-----------------------------------------------------------------
// 说明: 本例运行时,按下K1将读取并显示存放于Flash程序内存中的
// 320个字节数据及60个字数据.
//
//-----------------------------------------------------------------
#include “myfunc01.h”

//------------------------------------------------------------------
// 主程序
//------------------------------------------------------------------
int main()
{
INT8U Mem_byte;
INT16U Mem_word, i, j= 0;
char s[6];
Init_USART(51);
put_s("\n\n Press K1 to Start Read Date From Program Flash Memory…");
DDRB= 0x00; PORTB= 0xff;
DDRD= 0xff;
while(1) {
if(K1_DOWN()) {
put_s("\n AVR Program Memory Date Demo…\n");
put_s("\n ---------------------------------------------------------\n ");
for(i= 0, j= 0; i< sizeof(Flash_Byte_Array); i++) {
Mem_byte= pgm_read_byte(&Flash_Byte_Array[i]);
sprintf(s, "% 02X “, Mem_byte); put_s(s);
if(++j== 20) {
j= 0; put_s(”\n “);
}
}
put_s(”\n ---------------------------------------------------------\n ");
for(i= 0, j= 0; i< sizeof(Flash_Byte_Array); i++) {
Mem_byte= pgm_read_byte(&Flash_Byte_Array[i]);
sprintf(s, "% 04X “, Mem_word); put_s(s);
if(++j== 10) {
j= 0; put_s(”\n ");
}
}
}
}
}

myfunc01.h
//******************************************************************************************
#ifndef MYFUNC01_H
#define MYFUNC01_H

//#define F_CPU 4000000UL //4M晶振
#include
#include
#include
#define INT8U unsigned char
#define INT16U unsigned int

//按键定义
#define K1_DOWN() (PINB & _BV(PB0)) == 0x00

//存放于Flash程序内存中的字节数据(16*20 = 320个字节)
static INT8U Flash_Byte_Array[] =
{
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F
};

//存放于Flash程序内存中的字数据(10*6 = 60个字)
static INT16U Flash_Word_Array[] =
{
0x00AC,0x0198,0x0233,0x03BC,0x0480,0x0598,0x06BE,0x07F8,0x0899,0x09A0,
0x0ACC,0xFF1D,0xF2F3,0xF4F5,0xF6F7,0xF8F9,0xFAFB,0xFCFD,0xFEFF,0xD0D1,
0xD2D3,0xD4D5,0xD6D7,0xD8D9,0xDADB,0xDCDD,0xDEDF,0xE0E1,0xE2E3,0xE4E5,
0xE6E7,0xE8E9,0xEAEB,0xECED,0xEEF0,0xA1A2,0xA3A4,0xA5A6,0xA7A8,0xA9AA,
0xABAC,0xADAE,0xAF80,0x8182,0x8384,0x8586,0x8788,0x898A,0x8B8C,0x8D8E,
0x8F90,0x9192,0x9394,0x9596,0x9798,0xDADB,0xDCDD,0xDEDF,0xE0E1,0xE2E3
};

void Init_USART(INT16U baud);
void put_c(char c);

#endif

六,点击构建工程按钮,编译工程。(如下图7所示)
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第7张图片
图7

七,点击窗口左下方仿真按钮,可见信息在虚拟串口显示屏显示。 (如下图8,9,10所示)
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第8张图片
图8
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第9张图片
图9
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第10张图片
图10

八,选择release,点击构建工程按钮,编译工程生成Hex文件。(如下图11所示)
Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问_第11张图片
图11

附件下载:https://download.csdn.net/download/kaillen/12604720
Proteus8.9 SP2下载:https://download.csdn.net/download/kaillen/12459968
附件Proteus8.9 VSM Studio WINAVR编译器仿真ATmega16系列a25_Flash程序空间中数据访问在已安装Proteus8.9的计算机文件夹中打开即可
需要进一步了解,请加入QQ群:976235464

你可能感兴趣的:(C51,C语言,Proteus仿真,单片机,c语言,windows,小程序,安全)