标题:
有能在C里面对flash操作的源程序么?
[打印本页]
作者:
forthlab
时间:
2005-4-13 17:44
标题:
有能在C里面对flash操作的源程序么?
为何PE里面不提供flash的bean?flash的调试好像挺麻烦,如果有现成的,我就不费时间了.
现在用GT16.
现谢谢了[em11]
作者:
strongchen
时间:
2005-4-14 17:17
你可以将对FLASH操作的汇编程序直接插入C程序中,只要加个 asm { } 的标志就行了。
作者:
sampro
时间:
2005-4-15 11:58
我贴一个QY4的: //eeprom.c #include
#include "utils.h" #include "hidef.h" #include "globdefs.h" #define FLASH_CONTROL_LOCATION 0x88 #define CPU_BUS_CLOCK 5 #define CPU_SPEED_CONST (4*CPU_BUS_CLOCK) #define ERASE_ROUTINE_ADDRESS 0x2806 #define PROGR_ROUTINE_ADDRESS 0x2809 #define DELAY_CYCLES_OK 2000 #define INIT_CMD 0xFF void delay(word cycles); static struct { byte CTRLBYT; byte CPUSPD; word LADDR; byte DATA; } flash_control @FLASH_CONTROL_LOCATION; bool WriteByteInFlash(word address, byte data) { byte low_adr = SB(address, 1); byte high_adr = SB(address, 0); DisableInterrupts; flash_control.CTRLBYT = 0; flash_control.CPUSPD = CPU_SPEED_CONST; flash_control.LADDR = address; flash_control.DATA = data; asm { lda low_adr psha lda high_adr psha pulh pulx jsr PROGR_ROUTINE_ADDRESS } EnableInterrupts; return (*((byte*)(address)) == data); } bool EraseSegmentInFlash(word address) { byte low_adr = SB(address, 1); byte high_adr = SB(address, 0); DisableInterrupts; flash_control.CTRLBYT = 0; flash_control.CPUSPD = CPU_SPEED_CONST; flash_control.LADDR = address; flash_control.DATA = 0; asm { lda low_adr psha lda high_adr psha pulh pulx jsr ERASE_ROUTINE_ADDRESS } EnableInterrupts; return 1; } void Node_Process_Config_Data(word data) { byte cmd, res = 0; static byte prev_cmd = INIT_CMD; if ( #if (USE_BUTTON) BUTTON_BIT && #endif (FLASH_CONFIG_CHECK == (SB(data, HIGH_BYTE) & FLASH_CONFIG_CHECK_MASK))) { cmd = (SB(data, HIGH_BYTE) & FLASH_ADDRESS_MASK); switch (cmd) { case FLASH_RESET_CMD: if (prev_cmd != INIT_CMD) { prev_cmd = INIT_CMD; res = 1; } break; case FLASH_PAGE_ERASE_CMD: if (prev_cmd != cmd) res = EraseSegmentInFlash(FLASH_CONFIG_START_ADDRESS | cmd); prev_cmd = cmd; break; default: if (prev_cmd != cmd) res = WriteByteInFlash(FLASH_CONFIG_START_ADDRESS | cmd, SB(data, LOW_BYTE)); prev_cmd = cmd; break; } if (res) { ERROR_LED_BIT = 1; delay(DELAY_CYCLES_OK); ERROR_LED_BIT = 0; } } } //eeprom.h bool WriteByteInFlash(word address, byte data); bool EraseSegmentInFlash(word address); void Node_Process_Config_Data(word data);
作者:
sampro
时间:
2005-4-15 12:12
//globdefs.h
#define USE_BUTTON 0
#define CPU8PIN 1
#define CPU16PIN 2
#define CPU CPU16PIN
#if (CPU == CPU8PIN)
#define ERROR_LED_BIT PTA_PTA4
#define ERROR_LED_PORT PTA
#define ERROR_LED_DIR DDRA_DDRA4
#define DATA_IN_BIT PTA_PTA3
#define DATA_IN_PORT PTA
#define DATA_IN_DIR DDRA_DDRA3
#define DATA_OUT_BIT PTA_PTA5
#define DATA_OUT_PORT PTA
#define DATA_OUT_DIR DDRA_DDRA5
#define BUTTON_BIT PTA_PTA0
#define BUTTON_DIR DDRA_DDRA0
#define BUTTON_PULLUP PTAPUE_PTAPUE0
#elif (CPU == CPU16PIN)
#define ERROR_LED_BIT PTB_PTB5
#define ERROR_LED_PORT PTB
#define ERROR_LED_DIR DDRB_DDRB5
#define DATA_IN_BIT PTB_PTB7
#define DATA_IN_PORT PTB
#define DATA_IN_DIR DDRB_DDRB7
#define DATA_OUT_BIT PTB_PTB6
#define DATA_OUT_PORT PTB
#define DATA_OUT_DIR DDRB_DDRB6
#define BUTTON_BIT PTB_PTB4
#define BUTTON_DIR DDRB_DDRB4
#define BUTTON_PULLUP PTBPUE_PTBPUE4
#else
#error "CPU is undefined"
#endif
#define DIR_IN 0
#define DIR_OUT 1
#define DEBUG 1
#define FLASH_CONFIG_START_ADDRESS 0xEE00
#define FLASH_CONFIG_CHECK_MASK 0xF0
#define FLASH_ADDRESS_MASK 0x0F
#define FLASH_PAGE_ERASE_CMD 0x0E
#define FLASH_RESET_CMD 0x0F
#define FLASH_CONFIG_CHECK 0xA0
#define FRAME_DATA_PPP_IN_STOP (FLASH_CONFIG_START_ADDRESS+0)
#define FRAME_DATA_PPP_OUT_START (FLASH_CONFIG_START_ADDRESS+1)
#define FRAME_DATA_PPP_OUT_STOP (FLASH_CONFIG_START_ADDRESS+2)
#define FRAME_DATA_BROADCAST_OUT_START (FLASH_CONFIG_START_ADDRESS+3)
#define FRAME_DATA_BROADCAST_OUT_STOP (FLASH_CONFIG_START_ADDRESS+4)
#define BROADCAST_DATA_OUT_MASK (FLASH_CONFIG_START_ADDRESS+5)
#define BROADCAST_DATA_IN_MASK (FLASH_CONFIG_START_ADDRESS+6)
#define HIGH_BYTE 0
#define LOW_BYTE 1
#define CHECK_BUTTON() PTA_PTA3
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0