led.c

来自「深圳英培特EduKit-III实验箱实验程序。一共有10多个」· C语言 代码 · 共 50 行

C
50
字号
/*******************************************************
 * File Name: 	led.c
 * Description:  timing interrupt 	
 * Author:		
 * Date:		
 *******************************************************/
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
/*define port configuration register and port data register address*/

#define PCONB  (*(volatile unsigned *)0x01D20008)
#define PDATB  (*(volatile unsigned *)0x01D2000C)

int i=0;
/*you may modify the value of PDATB and change the led output.PB9 
and PB10 are corresponding pins to led1 OUTPUT and led2 OUTPUT.
Howover,each of port B pins is controled by register PDATB.SO you
may modify the corresponding bit of PDATB to control the led OUTPUT.*/

static void sig_alarm(int signumber)
{
	if(i==0)
	{
		PDATB=0XF6FF;
	     i=1;
}
	else
	{        
		PDATB=0XF9FF;
	     i=0;
}
	alarm(2);
}

int main(void)
{
	

	PCONB&=0XFFCF;
	if(signal(SIGALRM,sig_alarm)==SIG_ERR)
	{
		printf("some error occurs\n");
		return  1;
	}
	alarm(2);
	while(1);
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?