本帖最后由 holts 于 2012-12-26 10:41 编辑
很好的代码被你贴的, ,你应该象这样贴。
- /* MAIN.C file
- *
- * Copyright (c) 2002-2005 STMicroelectronics
- */
- #include "stm8s.h"
- #include <stdio.h>
- int _fctcpy(char name);
- main()
- {
- u8 block_buff[128] ={0};
- u8 i = 0;
- u8 c = 0;
- _fctcpy('F');
- CLK_DeInit();
- CLK_HSICmd(ENABLE);
- CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
- UART1_DeInit();
- UART1_Init((u32)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,
- UART1_SYNCMODE_CLOCK_DISABLE,UART1_MODE_TXRX_ENABLE);
- UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
- UART1_Cmd(ENABLE);
-
- GPIO_DeInit(GPIOD);
- GPIO_Init(GPIOD, GPIO_PIN_LNIB, GPIO_MODE_OUT_PP_LOW_FAST);
- for(i=0;i<128;i++)
- block_buff=i;
- FLASH_DeInit();
- FLASH_Unlock(FLASH_MEMTYPE_DATA);
- FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_TPROG);
- FLASH_ProgramBlock(0x0001, FLASH_MEMTYPE_DATA, FLASH_PROGRAMMODE_STANDARD, block_buff);
- FLASH_EraseBlock(0x0001, FLASH_MEMTYPE_DATA);
- c = FLASH_ReadByte(0x40ff);//读出值到变量中
- printf("c=%x\r\n",(u16)c);//打印
- c = FLASH_ReadByte(0x407f);
- printf("c=%x\r\n",(u16)c);
- c = FLASH_ReadByte(0x4080);
- printf("c=%x\r\n",(u16)c);
- c = FLASH_ReadByte(0x4100);
- printf("c=%x\r\n",(u16)c);
- _asm("rim");
- while (1)
- {
- GPIO_WriteHigh(GPIOD, GPIO_PIN_LNIB);
- }
- }
- char putchar (char c) //串口打印重定向,只要有这个函数,然后包含stdio.h就可以直接调用打印函数了,若有不成功时请把参数前强转为(u16)
- {
- if (c == '\n')
- {
- /* put '\r' to hardware here */
- /* Wait transmission is completed : otherwise the first data is not sent */
- while (!(UART1->SR & 0x40));
- UART1->DR = ('\r');
- /* Wait transmission is completed */
- while (!(UART1->SR & 0x40));
- }
- /* put c to hardware here */
- /* Wait transmission is completed : otherwise the first data is not sent */
- while (!(UART1->SR & 0x80));
- UART1->DR = (c);
- /* Wait transmission is completed */
- while (!(UART1->SR & 0x80));
- return (c);
- }
|