久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
不欺人,復制就能用 stm8 stvd驅動a4988驅動
[打印本頁]
作者:
chinarally@
時間:
2020-5-9 01:08
標題:
不欺人,復制就能用 stm8 stvd驅動a4988驅動
/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include <stm8s105k4.h> //驅動A4988
#define u8 unsigned char
#define u16 unsigned short
#define u32 unsigned long
#define v8 unsigned int
void delay_ms(v8 ms);
void delay_us(u8 t);
u8 key_scan(void);
void GPIO_Init(void);
void TIM1_Init(void);
u8 num;
int DIR;
main()
{
CLK_SWCR =0x02;
CLK_SWR =0xb4;
GPIO_Init();
TIM1_Init();
_asm("rim");
delay_ms(20);
while (1)
{
u8 i;
i=key_scan();
if(i==1)
{
PD_ODR|=0x08;
}
else
{
i==0;
PD_ODR&=0xf7;
}
}
}
void delay_ms(v8 ms)
{
v8 x,y;
for(x=ms;x>0;x--)
{
for(y=300;y>0;y--)
{
}
}
}
void delay_us(u8 t)
{
u8 m = t;
while(m--);
}
void GPIO_Init()
{
PD_DDR |=0x04; //PD2 為輸出引腳 1 STEP
PD_CR1 |=0x04; //PD2 為推挽輸出 1
PD_CR2 |=0x04; //PD2 為10MHZ速率1
PD_ODR &=0xfb; //PD2 為step輸出 0
PD_DDR |=0x08; //PD3 為輸出引腳 1 DIR
PD_CR1 |=0x08; //PD3 為推挽輸出 1
PD_CR2 &=0xf7; //PD3 為2MHZ速率 0
PD_DDR &=0xcf; //PD4,5 為輸入引腳 0
PD_CR1 |=0x30; //PD4,5 為若上拉輸入模式 1
PD_CR2 &=0xcf; //PD4,5 關外部中斷 0
}
void TIM1_Init(void)
{
TIM1_CR1 =0x80; // TIM1寄存器由預裝載寄存器緩沖
TIM1_PSCRH =0x00; //預分頻F(CK_CNT)=F(CK_PSC)/(PSCR[15:0]+1)
TIM1_PSCRL =0x9f; //159+1==160, 100khz
TIM1_IER=0x01; //中斷使能
TIM1_ARRH =125/256; //自動重裝載計數器125
TIM1_ARRL=125%256;
TIM1_CR1|=0x01; //TIM1寄存器CEN位為1
}
u8 key_scan()
{
u8 i;int c;
i=PD_IDR;
i&=0x30;
if(i==0x20)
{
delay_ms(10);
if(i ==0x20)
{
c==0;
}
return 1;
}
if(i ==0x10)
{
delay_ms(10);
if(i ==0x10)
{
c==1; //正
}
return 0;
}
}
@far @interrupt void TIM1_UPD_OVF_HandledInterrupt(void)//中斷
{
PD_ODR^=0x04;
TIM1_SR1&=0xfe;
}
/* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices
* Copyright (c) 2007 STMicroelectronics
*/
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
/* in order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction
*/
return;
}
extern void _stext(); /* startup routine */
extern @far @interrupt void TIM1_UPD_OVF_HandledInterrupt(void);
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, NonHandledInterrupt}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, TIM1_UPD_OVF_HandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
作者:
chinarally@
時間:
2020-5-9 01:13
謝謝管理員提醒,發帖只為與大家交流,不為積分。
大的化小,準備給小孩做個玩具。慢慢來。ad什么以后奉上。說明很詳細了。
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
日韩高清中文字幕
|
国产精品99久久久久久动医院
|
国产视频不卡一区
|
中文字幕国
|
91视频一区二区三区
|
国产美女在线观看
|
91精品国产综合久久婷婷香蕉
|
av久久
|
精品国产鲁一鲁一区二区张丽
|
一区二区三区视频在线免费观看
|
日韩三级免费网站
|
四虎影院在线播放
|
狠狠操狠狠色
|
一区二区免费视频
|
无码日韩精品一区二区免费
|
欧美日韩精品一区二区三区四区
|
国精产品一区一区三区免费完
|
日韩中文久久
|
黄色片网站国产
|
中文字幕精品一区二区三区精品
|
欧美日韩国产一区二区
|
欧美精品第一区
|
亚洲综合一区二区三区
|
国产精品毛片
|
久久综合一区二区三区
|
国产精品不卡
|
99久久精品免费看国产小宝寻花
|
成人永久免费视频
|
国产精品国产三级国产aⅴ中文
|
人人鲁人人莫人人爱精品
|
gogo肉体亚洲高清在线视
|
午夜视频一区二区三区
|
色婷婷久久久久swag精品
|
www.日韩欧美
|
操人网
|
91久久久久久久久久久久久
|
亚洲色欧美另类
|
天天天天操
|
99久久免费精品
|
新疆少妇videos高潮
|
eeuss国产一区二区三区四区
|