dipled.c

来自「基本回音程式,可以改变parameter来测试其速度和音响。」· C语言 代码 · 共 59 行

C
59
字号
/* 
 * Functions to access the CPLD controlled DIP and LED 
 * 
 * 31May07 .. initial version
 *
 * Note: 
 * - work for Large Memory Model only 
 * - to work in Small Memory Model, we need to use 
 *   the far_peek & far_poke (to be supported)
 * - ..
 */

#include "dipled.h"
 
#define CPLD_USER_REG (*((unsigned short *)0x300000))

// get the status of a DIP switch (0,1,2,3)
unsigned short DSK_DIP_read(unsigned short dip_num)
{
	unsigned short reg;
	reg = 1<<(dip_num+4); /* add 4 because DIP bits position are 4 to 7 */
   	reg &= CPLD_USER_REG; 

   	if (reg)
   		return 1;
   
   	return 0;   	
}
/*Joshuatok*/
// get the status of all DIP switches
unsigned short DSK_DIP_read_all(void)
{
	return (CPLD_USER_REG & 0x00f0)>>4; 
}


// set the LED on (0,1,2,3)
void DSK_LED_on(unsigned short led_num)
{
	CPLD_USER_REG =  CPLD_USER_REG | (1<<(led_num)); 
}

// set the LED off (0,1,2,3)
void DSK_LED_off(unsigned short led_num)
{
	CPLD_USER_REG =  CPLD_USER_REG & ~(1<<(led_num)); 
}


// set the LED based on the given pattern
void DSK_LED_set(unsigned short led_pat)
{
	unsigned short temp;
	temp = CPLD_USER_REG;
	temp &= ~0x000f; /* mask all LED bits */
	temp |= (led_pat & 0x000f);
	CPLD_USER_REG = temp;
}
/*Joshuatok*/

⌨️ 快捷键说明

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