Job Recruitment Website - Immigration policy - Write a square wave with output frequency of 2KHz with STM8S 105 single chip microcomputer, C language? Never used stm8 single-chip microcomputer, seeking introductory information. thank you
Write a square wave with output frequency of 2KHz with STM8S 105 single chip microcomputer, C language? Never used stm8 single-chip microcomputer, seeking introductory information. thank you
# including "STM8S 105K.h"
Typedef unsigned character u8;
Typedef unsigned int u16;
U 16 value;
void SystemInit(void)
{
CLK _ CKDIVR = 0x 08; // 16M internal RC divided by 2, and the system clock is 8M.
CLK _ PCK ENR 1 | = 0x 60; //Enable TIM2 and TIM3 to connect with the main frequency.
PD _ CR2 | = 0x80// Enables external interrupt of PD7 port.
}
void GPIO_init(void)
{
PD _ DDR = 0x 1F; //Configure the full output of the PD port direction register.
PD _ Cr 1 = 0x 1F; //Set PD as push-pull output.
}
Voidtim2 _ init (void)//tim2ch 1 working in mode1.
{
Tim 2 _ ccmr 1 = 0x 60; // PWM mode 1, TIM2 CH 1.
Tim 2 _ ccer 1 = 0x 03; // CC 1 is configured as an output.
TIM2 _ ARRH = 0x07// Configure the PWM resolution to 10 bit, and ARR=0x07D0.
Tim 2 _ ARRL = 0xd 0; // PWM frequency =8M/0x07D0=2000Hz.
Tim 2 _ Cr 1 | = 0x 0 1; //The counter is enabled to start counting.
}
Void initialization device (void)
{
ASM(“sim”);
system init();
GPIO _ init();
Tim 2 _ init();
_ ASM(“rim”); //Open host interrupt
}
Invalid master (invalid)
{
init _ devices();
while( 1)
Tim 2 _ CCR 1 = value; //Changing the value can change the frequency.
}
/****************************************************************************
* * * function name: @ near @ interruptvoid tli _ irqhandler (void)
* * * Function Description: Interrupt service program
Press the PD7 button to change the duty cycle.
*****************************************************************************/
@ near @ interrupt void TLI _ IRQ handler(void)
{
PD _ CR2 & amp= 0x7F///Turn off the external interrupt of PD7.
Value+= 50;
while(value & gt; 1000)
Value = 0;
PD _ CR2 | = 0x80// Enables external interrupt of PD7 port.
Return;
}
- Previous article:How can Canadian students get maple leaf cards?
- Next article:When will Baiyangdian dry up?
- Related articles
- What materials are needed to apply for a passport in 2023?
- Applicable scope of the lottery principle
- The experience of British immigrants
- What challenges has Mexico faced in recent years?
- What are the procedures for getting married in Chinese mainland and going to Taiwan Province Province to apply for a permit?
- Are Slovak countries suitable for immigrants?
- How to watch the live broadcast of Xinjiang 10?
- Swedish Alpine Immigrants
- Do you choose a college or a university to study in Canada?
- Mobile phone immigrants in Iceland