flash初始化子程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

/***********************************************************************************************Filename:flash.c*Description:flash数据读.*Author:ldm*Date:2013-11-29***********************************************************************************************/#includedoData.h#includemain.h#includeflash.h#includegprs.h#includePubUse.h#includeStructure.h//#includetimeapp.h#includestdlib.h#includehal_uart.h#includehal_timer.h#includestring.h//==============================================#defineFLASH_SPI_PAGESIZE0x100#defineFLASH_SPI_SECTORSZIE0x1000#defineFLASH_SPI_HIGHT_ADDR0x1000000externUPLOADSTATE_u_gcUpload;externTESTSTATE_u_gctest;externuint32addr_flash;//---------------------------------------------#pragmaudatabank3=0x300uint8SpiCheckBuf[256];#pragmaudataexternuint8buf0[256];externuint8DATABuf[GPRS_UART_BUF_SIZE];externvoiddelay_1us(uint16i);externvoiddelay_1ms(uint16i);/*********************************************************************************************************************************************************************************************/structbit_def{charb0:1;charb1:1;charb2:1;charb3:1;charb4:1;charb5:1;charb6:1;charb7:1;};unionbyte_def{structbit_defbit1;charbyte;};/***************************************************************************************Functionname:voidsleep_Flashcom(void);**Descriptions:invaildFlashcommunication.**inputparameters:none.**outputargument:none**Note:*************************************************************************************/voidsleep_PhoFlashcom(void)//无效SPI通信{PhoDataPortIn;SclkToPhoPortIn;//时钟脚输入状态SicToPhoPortIn;//数字脚输入状态PhoFlashCs_in;//选择脚输入ReadPho_off;//读拍照模块信号输出无效}voidsleep_RecFlashcom(void)//无效SPI通信{RecDataPortIn;SclkToRecPortIn;//时钟脚输入状态SicToRecPortIn;//数字脚输入状态RecFlashCs_in;//选择脚输入}/***************************************************************************************Functionname:ready_PhoFlashcomRead(void);**Descriptions:readyFlashcommunication.**inputparameters:none.**outputargument:none**Note:SPI操作准备*************************************************************************************/voidready_PhoFlashcomRead(void)//SPI操作前的准备{PhoFlashCs_out;//CS控制脚输出SclkToPhoPortOut;//时钟脚输出状态SicToPhoPortOut;//数字脚输出状态PhoFlashCs_inactive;//CS控制脚无效SclkToPho_off;//拉低芯片时钟线PhoDataPortIn;//拍照数据口输入}voidready_RecFlashcomRead(void)//SPI操作前的准备{RecFlashCs_out;//CS控制脚输出SclkToRecPortOut;//时钟脚输出状态SicToRecPortOut;//数字脚输出状态RecFlashCs_inactive;//CS控制脚无效SclkToRec_off;//拉低芯片时钟线RecDataPortIn;//录音数据口输入}/***************************************************************************************Functionname:voidready_PhoFlashcomWrite(void);**Descriptions:readyFlashcommunication.**inputparameters:none.**outputargument:none**Note:SPI操作准备*************************************************************************************/voidready_PhoFlashcomWrite(void)//SPI操作前的准备{PhoFlashCs_out;//CS控制脚输出SclkToPhoPortOut;//时钟脚输出状态SicToPhoPortOut;//数字脚输出状态PhoFlashCs_inactive;//CS控制脚无效//SicToPho_off;//数字脚低SclkToPho_off;//拉低芯片时钟线PhoDataPortOut;//拍照数据口输出}voidready_RecFlashcomWrite(void)//SPI操作前的准备{RecFlashCs_out;//CS控制脚输出SclkToRecPortOut;//时钟脚输出状态SicToRecPortOut;//数字脚输出状态RecFlashCs_inactive;//CS控制脚无效//SicToRec_off;//数字脚低SclkToRec_off;//拉低芯片时钟线RecDataPortOut;//拍照数据口输出}/***************************************************************************************Functionname:uint8read_1bytePhoFlash(void);**Descriptions:getbytefromFlashoutput**inputparameters:none**outputargument:returntheobtanedbytewhichtypeisuint8**Note:*************************************************************************************/uint8read_1bytePhoFlash(void)//从Flash读1字节数据{staticuint8i;ClrWdt();PhoDataPortIn;//拍照数据口输入SclkToPho_on;//拉高芯片时钟线delay_1us(5);i=PhoDataPort;SclkToPho_off;//拉低芯片时钟线delay_1us(5);returni;}uint8read_1byteRecFlash(void)//从Flash读1字节数据{staticuint8i;ClrWdt();RecDataPortIn;//拍照数据口输入SclkToRec_on;//拉高芯片时钟线delay_1us(5);i=RecDataPort;SclkToRec_off;//拉低芯片时钟线delay_1us(5);returni;}/***************************************************************************************Functionname:write_1bytePhoFlash(uint8PB_data);**Descriptions:writeonebytetotheFlash**inputparameters:PB_data:thedatareadytobewrite**outputargument:none.//**Note:PB_data:待写数据*************************************************************************************/voidwrite_1bytePhoFlash(uint8PB_data)//写1字节数据到Flash,SPI的写操作{uint8i;unionbyte_defLUB_data;LUB_data.byte=PB_data;//待写数据for(i=0;i8;i++){SicToPho=LUB_data.bit1.b7;//发送字节数据的高位delay_1us(5);SclkToPho_on;//拉高芯片时钟线,单片机发送数据LUB_data.byte=1;//取下一个位delay_1us(5);SclkToPho_off;//拉低芯片时钟线,Flash接收数据delay_1us(5);//us_delay(20);}delay_1us(10);ClrWdt();}voidwrite_1byteRecFlash(uint8PB_data)//写1字节数据到Flash,SPI的写操作{uint8i;unionbyte_defLUB_data;LUB_data.byte=PB_data;//待写数据for(i=0;i8;i++){SicToRec=LUB_data.bit1.b7;//发送字节数据的高位delay_1us(5);SclkToRec_on;//拉高芯片时钟线,单片机发送数据LUB_data.byte=1;//取下一个位delay_1us(5);SclkToRec_off;//拉低芯片时钟线,Flash接收数据delay_1us(5);//us_delay(20);}delay_1us(10);ClrWdt();}/**************************************

1 / 16
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功