打印
[Atmel]

用AtmelStudio6.2跑mega16例程(51)Flash

[复制链接]
670|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ddllxxrr|  楼主 | 2014-11-12 00:01 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 ddllxxrr 于 2014-11-12 00:23 编辑

本程序通过一个按键把FLASH里的数组通过串口打印出来。


程序清单:
/*
* GccApplication14.c
*
* Created: 2014-11-11 18:26:34
*  Author: Administrator
*/

#define F_CPU 4000000UL
#include <avr/pgmspace.h>
#include <stdio.h>
#include <avr/io.h>
#include <stdint.h>

typedef unsigned char PROGMEM prog_uchar;


#define  K1_DOWN() (PINB & _BV(PB0)) == 0x00

prog_int8_t Flash_Byte_Array[] = {0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,
                                  0xFC,0xFD,0xFE,0xFF};
                                                                  
prog_int16_t Flash_Word_Array[] =
{
   0x00AC,0x0198,0x0233,0x03BC,0x0480,0x0598,0x06BE,0x07F8,0x0899,0x09A0};
   
void Init_USART()
{
    UCSRB=_BV(TXEN); //允许发送
        UCSRC=_BV(URSEL)|_BV(UCSZ1)|_BV(UCSZ0);
        UBRRL = (F_CPU/9600/16-1)%256;
        UBRRH = (F_CPU/9600/16-1)/256;
}

void PutChar(char c)
{
    if(c=='\n') PutChar('\r');
        UDR = c;
        while(!(UCSRA & _BV(UDRE)));
}

void PutStr(char *s)
{
        while(*s) PutChar(*s ++);
}


int main(void)
{
    uint8_t Mem_byte;
        uint16_t Mem_word,i,j = 0;
        char s[6];
        Init_USART();
        PutStr("\n\n Press K1 to Start Read Data From Program Flash Memory...");
        DDRB = 0x00; PORTB = 0xFF;
        DDRD = 0xFF;
        while(1)
        {
                if(K1_DOWN())
                {
                        PutStr("\n AVR Program Memory Data Demo........\n");
                        PutStr("\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); PutStr(s);
                                if(++j==20)
                                {
                                       
                                        j=0;PutStr("\n");
                                }
                        }
                        PutStr("\n_______________________________________\n ");
                        for(i=0,j=0;i<sizeof(Flash_Word_Array);i++)
                        {
                                Mem_word = pgm_read_word(&Flash_Word_Array[i]);
                                sprintf(s,"%04X",Mem_word); PutStr(s);
                                if(++j == 10)
                                {
                                        j= 0; PutStr("\n");
                                }
                        }
                        
                }
        }
        
}


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2398

主题

6950

帖子

67

粉丝