本文來(lái)源電子發(fā)燒友社區(qū),作者:馬先生, 帖子地址:https://bbs.elecfans.com/jishu_2299040_1_1.html
有幸成功申請(qǐng)到了武漢芯源CW32F003FXSTARTKI開發(fā)板。
首先第一步閱讀對(duì)應(yīng)的手冊(cè)。
其中有一條闡述了ISP下載
接下來(lái)我們從官網(wǎng)上下載一個(gè)對(duì)應(yīng)的下載工具
1.選擇串口
2.選擇芯片
3.選擇對(duì)應(yīng)程序
4.按照下方大的紅色方框連線
連接串口和下載口的部分
其中ch340的電源也是要接的。
5.點(diǎn)擊在線編程。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define Set_CS PA00_SETHIGH() //設(shè)置CS0位高電平
#define Reset_CS PA00_SETLOW() //設(shè)置CS0位低電平
#define SetR_S PA01_SETHIGH() //設(shè)置RS(A0)位高電平
#define Reset_R_S PA01_SETLOW() //設(shè)置RS(A0)位低電平
#define Set_RES PA02_SETHIGH() //設(shè)置RES位高電平
#define Reset_RES PA02_SETLOW() //設(shè)置RES位高電平
#define Set_SCK PA03_SETHIGH() //設(shè)置SCLK位高電平
#define Reset_SCK PA03_SETLOW() //設(shè)置SCLK位低電平
#define Set_SDA PA05_SETHIGH() //設(shè)置SDA位高電平
#define Reset_SDA PA05_SETLOW() //設(shè)置SDA位低電平
unsigned char s0[42][16]=
{
/*--文字:0--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*--文字:1--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*--文字:2--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*--文字:3--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*--文字:4--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*--文字:5--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*--文字:6--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*--文字:7--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*--文字:8--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
/*--文字:9--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
/*--文字::10--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
/*--文字:小點(diǎn) 11 --*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
/*--調(diào)入了一幅圖像:大點(diǎn) 12--*/
/*--寬度x高度=8x16--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x78,0x78,0x78,0x00,0x00,
};
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void RTC_Configuration(void);
void ADC_Configuration(void);
void Sleep_Configuration(void);
void delay(uint16_t ms);
void RTC_IRQHandlerCallBack(void);
void LCD_GPIO_Config(void);
void initial_lcd(void);
void WRITE_STRING(unsigned char plat, unsigned char column, unsigned char p, unsigned char c);
/******************************************************************************
* Local variable definitions ('static') *
******************************************************************************/
uint32_t flag=0;
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
******************************************************************************
** briefMain function of project
**
** return uint32_t return value, if needed
**
** This sample toggle GPIOA.00
**
******************************************************************************/
/**
* @briefRTC時(shí)鐘測(cè)試,初始化日歷,使用間隔中斷0.5秒通過(guò)Log輸出日期時(shí)間
* @return int32_t
*/
int32_t main(void)
{
uint32_t cnt;
/* System Clocks Configuration */
RCC_Configuration();
/* GPIO Configuration */
GPIO_Configuration();
RTC_Configuration();
ADC_Configuration();
Sleep_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
LCD_GPIO_Config();
initial_lcd();
while(1)
{
WRITE_STRING(1,1,1,0);
}
}
/**
* @briefConfigures the different system clocks.
* @paramNone
* @retval None
*/
void RCC_Configuration(void)
{
RCC_HSI_Enable(RCC_HSIOSC_DIV6); // 8MHz主頻
RCC_LSI_Enable(); // 內(nèi)部低速時(shí)鐘作為RTC時(shí)鐘源,精度較差
// 如需要RTC走時(shí)精度高,需要使用外部高精度晶體作為時(shí)鐘源
// RCC_LSE_Enable(RCC_LSE_MODE_OSC, RCC_LSE_AMP_NORMAL, RCC_LSE_DRIVER_NORMAL);
RCC_APBPeriphClk_Enable1(RCC_APB1_PERIPH_RTC, ENABLE);
}
/**
* @briefConfigure the GPIO Pins.
* @paramNone
* @retval None
*/
void GPIO_Configuration(void)
{
// PA4 PB4喚醒
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.IT = GPIO_IT_FALLING |GPIO_IT_RISING; // 雙沿觸發(fā)中斷
GPIO_InitStructure.Mode = GPIO_MODE_INPUT_PULLUP; // 輸入上拉
GPIO_InitStructure.Pins = GPIO_PIN_4;
__RCC_GPIOA_CLK_ENABLE(); // 開GPIOA模塊的時(shí)鐘
__RCC_GPIOB_CLK_ENABLE(); // 開GPIOB模塊的時(shí)鐘
GPIO_Init(CW_GPIOA, &GPIO_InitStructure);
GPIO_Init(CW_GPIOB, &GPIO_InitStructure);
GPIO_ConfigFilter(CW_GPIOA, GPIO_PIN_4, GPIO_FLTCLK_LSI); // 休眠時(shí),中斷喚醒通過(guò)LSI時(shí)鐘去抖動(dòng)。
GPIO_ConfigFilter(CW_GPIOB, GPIO_PIN_4, GPIO_FLTCLK_LSI);
CW_GPIOA->ICR = 0x0000;
CW_GPIOB->ICR = 0x0000; // 清中斷標(biāo)志
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pins = GPIO_PIN_8 | GPIO_PIN_9;
GPIO_Init(CW_GPIOB, &GPIO_InitStructure);
PB08_SETLOW();
PB09_SETHIGH();
}
void RTC_Configuration(void)
{
RTC_InitTypeDef RTC_InitStruct = {0};
RTC_AlARMTypeDef RTC_AlarmStruct = {0};
__RCC_RTC_CLK_ENABLE(); // 開RTC模塊的時(shí)鐘
RCC_LSI_Enable(); // 選擇LSI為RTC時(shí)鐘,在配置RTC時(shí)鐘前,時(shí)鐘源必須有效
RTC_InitStruct.DateStruct.Day = 0x21; //設(shè)置日期,DAY、MONTH、YEAR必須為BCD方式,星期為0~6,代表星期日,星期一至星期六
RTC_InitStruct.DateStruct.Month = RTC_Month_July;
RTC_InitStruct.DateStruct.Week = RTC_Weekday_Thursday;
RTC_InitStruct.DateStruct.Year = 0x22; // 2022-7-21
RTC_InitStruct.TimeStruct.Hour = 0x2; //設(shè)置時(shí)間,HOUR、MINIUTE、SECOND必須為BCD方式,用戶須保證HOUR、AMPM、H24之間的關(guān)聯(lián)正確性
RTC_InitStruct.TimeStruct.Minute = 0x58;
RTC_InitStruct.TimeStruct.Second = 0x55;
RTC_InitStruct.TimeStruct.AMPM = RTC_H12_PM;
RTC_InitStruct.TimeStruct.H24 = 0; // 12小時(shí)制 PM 2:58:55
RTC_InitStruct.RTC_ClockSource = RTC_RTCCLK_FROM_LSI;
RTC_Init(&RTC_InitStruct); //用戶需選定需要使用的時(shí)鐘源
/* 設(shè)置鬧鐘在30秒鬧一次 */
RTC_AlarmStruct.RTC_AlarmMask = RTC_AlarmMask_All & (~RTC_AlarmMask_Seconds); // 和秒位匹配
RTC_AlarmStruct.RTC_AlarmTime.Hour = 0x01;
RTC_AlarmStruct.RTC_AlarmTime.Minute = 0x01;
RTC_AlarmStruct.RTC_AlarmTime.Second = 0x30;
RTC_SetAlarm(RTC_Alarm_A, &RTC_AlarmStruct);
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
RTC_ITConfig(RTC_IT_ALARMA, ENABLE);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure ={0};
ADC_WdtTypeDef ADC_WdtStructure = {0};
ADC_SingleChTypeDef ADC_SingleChStructure = {0};
__RCC_ADC_CLK_ENABLE(); // ADC模塊時(shí)鐘打開
//ADC默認(rèn)值初始化
ADC_StructInit(&ADC_InitStructure);
//ADC工作時(shí)鐘配置
ADC_InitStructure.ADC_ClkDiv = ADC_Clk_Div2; // ADCCLK= 4MHz
ADC_InitStructure.ADC_VrefSel = ADC_Vref_VDDA;
//ADC模擬看門狗通道初始化
ADC_WdtInit(&ADC_WdtStructure);
//配置單通道轉(zhuǎn)換模式
ADC_SingleChStructure.ADC_DiscardEn = ADC_DiscardNull;
ADC_SingleChStructure.ADC_Chmux = ADC_VddaDiV3Input; //選擇ADC轉(zhuǎn)換通道 VDDA/3
ADC_SingleChStructure.ADC_InitStruct = ADC_InitStructure;
ADC_SingleChStructure.ADC_WdtStruct = ADC_WdtStructure;
ADC_SingleChOneModeCfg(&ADC_SingleChStructure);
ADC_AutoStop(ADC_AutoStopEnable); // 低功耗,使能ADC的自動(dòng)關(guān)閉模式
ADC_ClearITPendingAll();
//ADC使能
ADC_Enable();
ADC_SoftwareStartConvCmd(ENABLE);
}
void Sleep_Configuration(void)
{
PWR_InitTypeDef PWR_InitStructure;
PWR_InitStructure.PWR_Sevonpend = PWR_Sevonpend_Disable;
PWR_InitStructure.PWR_SleepDeep = PWR_SleepDeep_Enable;
PWR_InitStructure.PWR_SleepOnExit = PWR_SleepOnExit_Disable;
PWR_Config(&PWR_InitStructure);
}
/**
* @briefConfigure the nested vectored interrupt controller.
* @paramNone
* @retval None
*/
void NVIC_Configuration(void)
{
__disable_irq();
NVIC_EnableIRQ(RTC_IRQn);
NVIC_EnableIRQ(GPIOA_IRQn);
NVIC_EnableIRQ(GPIOB_IRQn);
__enable_irq();
}
void delay(uint16_t ms)
{
uint32_t i;
for( ; ms >0; ms--)
{
i = 796;
while(i--);
}
}
void RTC_IRQHandlerCallBack(void)
{
if (RTC_GetITState(RTC_IT_ALARMA))
{
RTC_ClearITPendingBit(RTC_IT_ALARMA);
flag |= 1;
}
}
void GPIOA_IRQHandlerCallBack()
{
CW_GPIOA->ICR = 0x0000;
flag |= 1<<1;
}
void GPIOB_IRQHandlerCallBack()
{
CW_GPIOB->ICR = 0x0000;
flag |= 1<<2;
}
///////////////////////////////////////////////////////////////////////////////////
void LCD_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
CW_SYSCTRL->AHBEN_f.GPIOA = 1; //Open GPIOA Clk
GPIO_InitStruct.Pins = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3| GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init( CW_GPIOA, &GPIO_InitStruct);
}
/*寫指令到LCD模塊*/
void transfer_command(int cmd)
{
char i;
Reset_CS;
Reset_R_S;
for (i = 0; i < 8; i++)
{
Reset_SCK;
if ((cmd << i) & 0x80)
Set_SDA;
else
Reset_SDA;
Set_SCK;
}
//A0 = 1;
Set_CS;
}
/*寫數(shù)據(jù)到LCD模塊*/
void transfer_data(int data)
{
char i;
Reset_CS;
SetR_S;
for (i = 0; i < 8; i++)
{
Reset_SCK;
if ((data << i) & 0x80)
Set_SDA;
else
Reset_SDA;
Set_SCK;
}
Set_CS;
}
//延時(shí)
//LCD模塊初始化
void initial_lcd(void)
{
Reset_CS;
Reset_RES; /*低電平復(fù)位*/
delay(20);
Set_RES; /*復(fù)位完畢*/
delay(20);
transfer_command(0xe2); /*軟復(fù)位*/
delay(50);
transfer_command(0x2c);/*升壓步聚1*/
delay(50);
transfer_command(0x2e);/*升壓步聚2*/
delay(50);
transfer_command(0x2f);/*升壓步聚3*/
delay(50);
transfer_command(0x25);/*0x24粗調(diào)對(duì)比度,可設(shè)置范圍0x20~0x27*/
transfer_command(0x81);/*微調(diào)對(duì)比度*/
transfer_command(0x28);/*0x28,微調(diào)對(duì)比度的值,可設(shè)置范圍0x00~0x3f1f*/
transfer_command(0xa2);/*1/9偏壓比(bias)*/
transfer_command(0xc0);/*行掃描順序:從上到下*/
transfer_command(0xa1);/*列掃描順序:從左到右*/
transfer_command(0x40);/*起始行:第一行開始*/
transfer_command(0xaf);/*開顯示*/
Set_CS;
}
/////////////////////////////////////////////////////////////////////////////////////
//==============寫顯示==============================
//plat x坐標(biāo); column y坐標(biāo); xs數(shù)組選擇;p數(shù)組位置;c是否反白顯示
void WRITE_STRING(unsigned char plat, unsigned char column, unsigned char p, unsigned char c)
{
unsigned char page,page1,col,col_h,col_l;
unsigned char i,a,j=0;
unsigned char temp1,temp2;
temp1 = 8; temp2 = 2;
page1= plat*2;
page=page1+0xb0;
col=column*temp1;
col_h=((col>>4)|0xf0)&0x1f;
col_l=col&0x0f;
for(a = 0; a < temp2; a++)
{
transfer_command(col_h);
transfer_command(col_l);
transfer_command(page+a);
for(i = 0;i < temp1; i ++ )
{
if(c == 0){transfer_data(s0[p][j++]);}
if(c == 1){transfer_data(~(s0[p][j++]));}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
#ifdefUSE_FULL_ASSERT
/**
* @briefReports the name of the source file and the source line number
* where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %drn", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
有幸成功申請(qǐng)到了武漢芯源CW32F003FXSTARTKI開發(fā)板。
首先第一步閱讀對(duì)應(yīng)的手冊(cè)。
其中有一條闡述了ISP下載

接下來(lái)我們從官網(wǎng)上下載一個(gè)對(duì)應(yīng)的下載工具
1.選擇串口
2.選擇芯片
3.選擇對(duì)應(yīng)程序
4.按照下方大的紅色方框連線
連接串口和下載口的部分
其中ch340的電源也是要接的。
5.點(diǎn)擊在線編程。

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define Set_CS PA00_SETHIGH() //設(shè)置CS0位高電平
#define Reset_CS PA00_SETLOW() //設(shè)置CS0位低電平
#define SetR_S PA01_SETHIGH() //設(shè)置RS(A0)位高電平
#define Reset_R_S PA01_SETLOW() //設(shè)置RS(A0)位低電平
#define Set_RES PA02_SETHIGH() //設(shè)置RES位高電平
#define Reset_RES PA02_SETLOW() //設(shè)置RES位高電平
#define Set_SCK PA03_SETHIGH() //設(shè)置SCLK位高電平
#define Reset_SCK PA03_SETLOW() //設(shè)置SCLK位低電平
#define Set_SDA PA05_SETHIGH() //設(shè)置SDA位高電平
#define Reset_SDA PA05_SETLOW() //設(shè)置SDA位低電平
unsigned char s0[42][16]=
{
/*--文字:0--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*--文字:1--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*--文字:2--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*--文字:3--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*--文字:4--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*--文字:5--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*--文字:6--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*--文字:7--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*--文字:8--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
/*--文字:9--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
/*--文字::10--*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
/*--文字:小點(diǎn) 11 --*/
/*--宋體12;此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,
/*--調(diào)入了一幅圖像:大點(diǎn) 12--*/
/*--寬度x高度=8x16--*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x78,0x78,0x78,0x00,0x00,
};
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void RTC_Configuration(void);
void ADC_Configuration(void);
void Sleep_Configuration(void);
void delay(uint16_t ms);
void RTC_IRQHandlerCallBack(void);
void LCD_GPIO_Config(void);
void initial_lcd(void);
void WRITE_STRING(unsigned char plat, unsigned char column, unsigned char p, unsigned char c);
/******************************************************************************
* Local variable definitions ('static') *
******************************************************************************/
uint32_t flag=0;
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
******************************************************************************
** briefMain function of project
**
** return uint32_t return value, if needed
**
** This sample toggle GPIOA.00
**
******************************************************************************/
/**
* @briefRTC時(shí)鐘測(cè)試,初始化日歷,使用間隔中斷0.5秒通過(guò)Log輸出日期時(shí)間
* @return int32_t
*/
int32_t main(void)
{
uint32_t cnt;
/* System Clocks Configuration */
RCC_Configuration();
/* GPIO Configuration */
GPIO_Configuration();
RTC_Configuration();
ADC_Configuration();
Sleep_Configuration();
/* NVIC Configuration */
NVIC_Configuration();
LCD_GPIO_Config();
initial_lcd();
while(1)
{
WRITE_STRING(1,1,1,0);
}
}
/**
* @briefConfigures the different system clocks.
* @paramNone
* @retval None
*/
void RCC_Configuration(void)
{
RCC_HSI_Enable(RCC_HSIOSC_DIV6); // 8MHz主頻
RCC_LSI_Enable(); // 內(nèi)部低速時(shí)鐘作為RTC時(shí)鐘源,精度較差
// 如需要RTC走時(shí)精度高,需要使用外部高精度晶體作為時(shí)鐘源
// RCC_LSE_Enable(RCC_LSE_MODE_OSC, RCC_LSE_AMP_NORMAL, RCC_LSE_DRIVER_NORMAL);
RCC_APBPeriphClk_Enable1(RCC_APB1_PERIPH_RTC, ENABLE);
}
/**
* @briefConfigure the GPIO Pins.
* @paramNone
* @retval None
*/
void GPIO_Configuration(void)
{
// PA4 PB4喚醒
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.IT = GPIO_IT_FALLING |GPIO_IT_RISING; // 雙沿觸發(fā)中斷
GPIO_InitStructure.Mode = GPIO_MODE_INPUT_PULLUP; // 輸入上拉
GPIO_InitStructure.Pins = GPIO_PIN_4;
__RCC_GPIOA_CLK_ENABLE(); // 開GPIOA模塊的時(shí)鐘
__RCC_GPIOB_CLK_ENABLE(); // 開GPIOB模塊的時(shí)鐘
GPIO_Init(CW_GPIOA, &GPIO_InitStructure);
GPIO_Init(CW_GPIOB, &GPIO_InitStructure);
GPIO_ConfigFilter(CW_GPIOA, GPIO_PIN_4, GPIO_FLTCLK_LSI); // 休眠時(shí),中斷喚醒通過(guò)LSI時(shí)鐘去抖動(dòng)。
GPIO_ConfigFilter(CW_GPIOB, GPIO_PIN_4, GPIO_FLTCLK_LSI);
CW_GPIOA->ICR = 0x0000;
CW_GPIOB->ICR = 0x0000; // 清中斷標(biāo)志
GPIO_InitStructure.IT = GPIO_IT_NONE;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pins = GPIO_PIN_8 | GPIO_PIN_9;
GPIO_Init(CW_GPIOB, &GPIO_InitStructure);
PB08_SETLOW();
PB09_SETHIGH();
}
void RTC_Configuration(void)
{
RTC_InitTypeDef RTC_InitStruct = {0};
RTC_AlARMTypeDef RTC_AlarmStruct = {0};
__RCC_RTC_CLK_ENABLE(); // 開RTC模塊的時(shí)鐘
RCC_LSI_Enable(); // 選擇LSI為RTC時(shí)鐘,在配置RTC時(shí)鐘前,時(shí)鐘源必須有效
RTC_InitStruct.DateStruct.Day = 0x21; //設(shè)置日期,DAY、MONTH、YEAR必須為BCD方式,星期為0~6,代表星期日,星期一至星期六
RTC_InitStruct.DateStruct.Month = RTC_Month_July;
RTC_InitStruct.DateStruct.Week = RTC_Weekday_Thursday;
RTC_InitStruct.DateStruct.Year = 0x22; // 2022-7-21
RTC_InitStruct.TimeStruct.Hour = 0x2; //設(shè)置時(shí)間,HOUR、MINIUTE、SECOND必須為BCD方式,用戶須保證HOUR、AMPM、H24之間的關(guān)聯(lián)正確性
RTC_InitStruct.TimeStruct.Minute = 0x58;
RTC_InitStruct.TimeStruct.Second = 0x55;
RTC_InitStruct.TimeStruct.AMPM = RTC_H12_PM;
RTC_InitStruct.TimeStruct.H24 = 0; // 12小時(shí)制 PM 2:58:55
RTC_InitStruct.RTC_ClockSource = RTC_RTCCLK_FROM_LSI;
RTC_Init(&RTC_InitStruct); //用戶需選定需要使用的時(shí)鐘源
/* 設(shè)置鬧鐘在30秒鬧一次 */
RTC_AlarmStruct.RTC_AlarmMask = RTC_AlarmMask_All & (~RTC_AlarmMask_Seconds); // 和秒位匹配
RTC_AlarmStruct.RTC_AlarmTime.Hour = 0x01;
RTC_AlarmStruct.RTC_AlarmTime.Minute = 0x01;
RTC_AlarmStruct.RTC_AlarmTime.Second = 0x30;
RTC_SetAlarm(RTC_Alarm_A, &RTC_AlarmStruct);
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
RTC_ITConfig(RTC_IT_ALARMA, ENABLE);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure ={0};
ADC_WdtTypeDef ADC_WdtStructure = {0};
ADC_SingleChTypeDef ADC_SingleChStructure = {0};
__RCC_ADC_CLK_ENABLE(); // ADC模塊時(shí)鐘打開
//ADC默認(rèn)值初始化
ADC_StructInit(&ADC_InitStructure);
//ADC工作時(shí)鐘配置
ADC_InitStructure.ADC_ClkDiv = ADC_Clk_Div2; // ADCCLK= 4MHz
ADC_InitStructure.ADC_VrefSel = ADC_Vref_VDDA;
//ADC模擬看門狗通道初始化
ADC_WdtInit(&ADC_WdtStructure);
//配置單通道轉(zhuǎn)換模式
ADC_SingleChStructure.ADC_DiscardEn = ADC_DiscardNull;
ADC_SingleChStructure.ADC_Chmux = ADC_VddaDiV3Input; //選擇ADC轉(zhuǎn)換通道 VDDA/3
ADC_SingleChStructure.ADC_InitStruct = ADC_InitStructure;
ADC_SingleChStructure.ADC_WdtStruct = ADC_WdtStructure;
ADC_SingleChOneModeCfg(&ADC_SingleChStructure);
ADC_AutoStop(ADC_AutoStopEnable); // 低功耗,使能ADC的自動(dòng)關(guān)閉模式
ADC_ClearITPendingAll();
//ADC使能
ADC_Enable();
ADC_SoftwareStartConvCmd(ENABLE);
}
void Sleep_Configuration(void)
{
PWR_InitTypeDef PWR_InitStructure;
PWR_InitStructure.PWR_Sevonpend = PWR_Sevonpend_Disable;
PWR_InitStructure.PWR_SleepDeep = PWR_SleepDeep_Enable;
PWR_InitStructure.PWR_SleepOnExit = PWR_SleepOnExit_Disable;
PWR_Config(&PWR_InitStructure);
}
/**
* @briefConfigure the nested vectored interrupt controller.
* @paramNone
* @retval None
*/
void NVIC_Configuration(void)
{
__disable_irq();
NVIC_EnableIRQ(RTC_IRQn);
NVIC_EnableIRQ(GPIOA_IRQn);
NVIC_EnableIRQ(GPIOB_IRQn);
__enable_irq();
}
void delay(uint16_t ms)
{
uint32_t i;
for( ; ms >0; ms--)
{
i = 796;
while(i--);
}
}
void RTC_IRQHandlerCallBack(void)
{
if (RTC_GetITState(RTC_IT_ALARMA))
{
RTC_ClearITPendingBit(RTC_IT_ALARMA);
flag |= 1;
}
}
void GPIOA_IRQHandlerCallBack()
{
CW_GPIOA->ICR = 0x0000;
flag |= 1<<1;
}
void GPIOB_IRQHandlerCallBack()
{
CW_GPIOB->ICR = 0x0000;
flag |= 1<<2;
}
///////////////////////////////////////////////////////////////////////////////////
void LCD_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
CW_SYSCTRL->AHBEN_f.GPIOA = 1; //Open GPIOA Clk
GPIO_InitStruct.Pins = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3| GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init( CW_GPIOA, &GPIO_InitStruct);
}
/*寫指令到LCD模塊*/
void transfer_command(int cmd)
{
char i;
Reset_CS;
Reset_R_S;
for (i = 0; i < 8; i++)
{
Reset_SCK;
if ((cmd << i) & 0x80)
Set_SDA;
else
Reset_SDA;
Set_SCK;
}
//A0 = 1;
Set_CS;
}
/*寫數(shù)據(jù)到LCD模塊*/
void transfer_data(int data)
{
char i;
Reset_CS;
SetR_S;
for (i = 0; i < 8; i++)
{
Reset_SCK;
if ((data << i) & 0x80)
Set_SDA;
else
Reset_SDA;
Set_SCK;
}
Set_CS;
}
//延時(shí)
//LCD模塊初始化
void initial_lcd(void)
{
Reset_CS;
Reset_RES; /*低電平復(fù)位*/
delay(20);
Set_RES; /*復(fù)位完畢*/
delay(20);
transfer_command(0xe2); /*軟復(fù)位*/
delay(50);
transfer_command(0x2c);/*升壓步聚1*/
delay(50);
transfer_command(0x2e);/*升壓步聚2*/
delay(50);
transfer_command(0x2f);/*升壓步聚3*/
delay(50);
transfer_command(0x25);/*0x24粗調(diào)對(duì)比度,可設(shè)置范圍0x20~0x27*/
transfer_command(0x81);/*微調(diào)對(duì)比度*/
transfer_command(0x28);/*0x28,微調(diào)對(duì)比度的值,可設(shè)置范圍0x00~0x3f1f*/
transfer_command(0xa2);/*1/9偏壓比(bias)*/
transfer_command(0xc0);/*行掃描順序:從上到下*/
transfer_command(0xa1);/*列掃描順序:從左到右*/
transfer_command(0x40);/*起始行:第一行開始*/
transfer_command(0xaf);/*開顯示*/
Set_CS;
}
/////////////////////////////////////////////////////////////////////////////////////
//==============寫顯示==============================
//plat x坐標(biāo); column y坐標(biāo); xs數(shù)組選擇;p數(shù)組位置;c是否反白顯示
void WRITE_STRING(unsigned char plat, unsigned char column, unsigned char p, unsigned char c)
{
unsigned char page,page1,col,col_h,col_l;
unsigned char i,a,j=0;
unsigned char temp1,temp2;
temp1 = 8; temp2 = 2;
page1= plat*2;
page=page1+0xb0;
col=column*temp1;
col_h=((col>>4)|0xf0)&0x1f;
col_l=col&0x0f;
for(a = 0; a < temp2; a++)
{
transfer_command(col_h);
transfer_command(col_l);
transfer_command(page+a);
for(i = 0;i < temp1; i ++ )
{
if(c == 0){transfer_data(s0[p][j++]);}
if(c == 1){transfer_data(~(s0[p][j++]));}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
#ifdefUSE_FULL_ASSERT
/**
* @briefReports the name of the source file and the source line number
* where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %drn", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。
舉報(bào)投訴
-
開發(fā)板試用
+關(guān)注
關(guān)注
3文章
303瀏覽量
2750 -
CW32
+關(guān)注
關(guān)注
1文章
299瀏覽量
1850
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
熱點(diǎn)推薦
請(qǐng)問(wèn)芯源的CW32F030可以使用JLINK進(jìn)行開發(fā)調(diào)試嗎?
芯源的芯片CW32F030 價(jià)格挺便宜的,看芯片手冊(cè),性能也不錯(cuò),正打算試用一下,請(qǐng)問(wèn)可以使用JLINK開發(fā)調(diào)試嗎?
發(fā)表于 12-16 07:19
Cortex-M0+通用 MCU CW32F系列產(chǎn)品介紹
了武漢芯源的快速發(fā)展之路。
CW32F003系列封裝展示
CW32F系列主要功能
CW32F003
發(fā)表于 12-12 06:22
基于武漢芯源CW32F030C8T6直流無(wú)刷電機(jī)評(píng)估開發(fā)板的設(shè)計(jì)方案
武漢芯源半導(dǎo)體在2021年推出的CW32F030系列微控制器嗎優(yōu)勢(shì),該控制器全面實(shí)現(xiàn)-40℃-105℃超寬溫度范圍和1.65V-5.5V超寬工作電壓,面向最廣泛的各種
發(fā)表于 12-04 06:16
一起來(lái)玩轉(zhuǎn)CW32L011無(wú)刷直流電機(jī)驅(qū)動(dòng)開發(fā)板
一、測(cè)評(píng)前言
前一陣子武漢芯源CW32生態(tài)社區(qū)搞活動(dòng),基于CW32L011推出了一款產(chǎn)品級(jí)的無(wú)刷直流電機(jī)
發(fā)表于 08-21 23:04
CW32L011電機(jī)驅(qū)動(dòng)電機(jī)控制開發(fā)板-硬件1
CW32L011電機(jī)驅(qū)動(dòng)電機(jī)控制開發(fā)板-硬件介紹 后面有軟件分析
有獎(jiǎng)丨米爾 瑞芯微RK3506開發(fā)板免費(fèi)試用來(lái)啦!
米爾與瑞芯微合作發(fā)布的新品基于瑞芯微RK3506應(yīng)用處理器的MYD-YR3506開發(fā)板免費(fèi)試用名額增加啦
有獎(jiǎng)丨米爾 瑞芯微RK3506開發(fā)板免費(fèi)試用
米爾與瑞芯微合作發(fā)布的新品基于瑞芯微RK3506應(yīng)用處理器的MYD-YR3506開發(fā)板免費(fèi)試用名額來(lái)啦~~米爾提供了3塊價(jià)值299元的MYD
有獎(jiǎng)丨米爾 瑞芯微RK3562開發(fā)板免費(fèi)試用新增名額!
米爾與瑞芯微合作發(fā)布的新品基于瑞芯微RK3562應(yīng)用處理器的MYD-YR3562開發(fā)板免費(fèi)試用名額增加
有獎(jiǎng)丨米爾 NXP i.MX91開發(fā)板免費(fèi)試用來(lái)啦
米爾與NXP合作發(fā)布的新品基于NXPi.MX91應(yīng)用處理器的MYD-LMX91開發(fā)板免費(fèi)試用名額來(lái)啦~~米爾提供了3套價(jià)值588元的MYD-LMX91開發(fā)板發(fā)起
武漢芯源半導(dǎo)體CW32L010在兩輪車儀表的應(yīng)用介紹
介紹的兩輪車儀表方案是無(wú)錫梓軒電子基于武漢芯源半導(dǎo)體 CW32L010F8P6開發(fā),適用于小規(guī)格電動(dòng)車儀表方案,實(shí)現(xiàn)車輛速度、累計(jì)里程、單次
發(fā)表于 05-13 14:06
免費(fèi)丨米爾 STM32MP257開發(fā)板有獎(jiǎng)試用
米爾與ST合作發(fā)布的新品基于STM32MP257應(yīng)用處理器的MYD-LD25X開發(fā)板免費(fèi)試用活動(dòng)來(lái)啦~~米爾提供了2塊價(jià)值488元的MYD-LD25X開發(fā)板發(fā)起
有獎(jiǎng)丨米爾 瑞芯微YR3562開發(fā)板免費(fèi)試用
米爾與瑞芯微合作發(fā)布的新品基于瑞芯微RK3562應(yīng)用處理器的MYD-YR3562開發(fā)板免費(fèi)試用活動(dòng)來(lái)啦~~米爾提供了3塊價(jià)值599元的MYD
【武漢芯源CW32F003FXSTARTKI開發(fā)板免費(fèi)試用體驗(yàn)】ISP下載+12864軟件模擬驅(qū)動(dòng)
評(píng)論