Keil5及Proteus—跑马灯实验
Keil5
Proteus
Keil5
主函数test.c
int main(void)
{
Stm32_Clock_Init(9); //系统时钟设置
delay_init(72); //延时初始化
LED_Init(); //初始化与LED连接的硬件接口
while(1)
{
LED0=0;
LED1=1;
delay_ms(3000);
LED0=1;
LED1=0;
delay_ms(3000);
}
}
led.c
void LED_Init(void)
{
RCC->APB2ENR|=1<<2; //使能PORTA时钟
RCC->APB2ENR|=1<<5; //使能PORTD时钟
GPIOA->CRH&=0XFFFFFFF0;
GPIOA->CRH|=0X00000003;//PA8 推挽输出
GPIOA->ODR|=1<<8; //PA8 输出高
GPIOD->CRL&=0XFFFFF0FF;
GPIOD->CRL|=0X00000300;//PD.2推挽输出
GPIOD->ODR|=1<<2; //PD.2输出高
}
led.h
#define LED0 PAout(8) // PA8
#define LED1 PDout(2) // PD2
void LED_Init(void); //初始化
#endif
stm32开发板## Proteus
keil4中的代码
#include <reg51.h> //包含头文件
#include <intrins.h> //包含移位库函数头文件
void delay(void) //延时函数
{
unsigned char i,j;
for(i = 0;i < 252;i++)
for(j = 0;j < 252;j++);
}
void main(void)
{
unsigned char i;
P2 = 0x01; //P2口初始化
while(1)
{
for(i = 0;i < 7;i++)
{
P2 = _crol_(P2,1); //P2端口向左循环移动1位
delay();
}
for(i = 0;i < 7;i++)
{
P2 = _cror_(P2,1); //P2端口向右循环移动1位
delay();
}
}
}
Proteus中的仿真结果