📄 util.c
字号:
// Utility functions
#include <LPC213x.H> // LPC21xx definitions
#include <bsp.h> // include board support package
#include <stdio.h>
void set_LED(char led_no, char led_cmd) {
if (led_cmd == ON) {
if (led_no == ALL) IOSET1 = 0x00FF0000;
else IOSET1 = (0x00010000 << led_no);
}
if (led_cmd == OFF) {
if (led_no == ALL) IOCLR1 = 0x00FF0000;
else IOCLR1 = (0x00010000 << led_no);
}
}
int kp_printf(const char *fmt) {
if ((U1SCR & 0x04) == 0x04) printf(fmt);
return(0);
}
char ntoc(unsigned char x) //given a single digit, return a character for that
{ //digit.
switch (x)
{
case 9 : return('9');
case 8 : return('8');
case 7 : return('7');
case 6 : return('6');
case 5 : return('5');
case 4 : return('4');
case 3 : return('3');
case 2 : return('2');
case 1 : return('1');
case 0 : return('0');
}
return('?'); //return an "F" if if digit is grater than 9
}
char htoc(unsigned char x) //given a single digit, return a character for that
{ //digit.
switch (x)
{
case 15 : return('F');
case 14 : return('E');
case 13 : return('D');
case 12 : return('C');
case 11 : return('B');
case 10 : return('A');
case 9 : return('9');
case 8 : return('8');
case 7 : return('7');
case 6 : return('6');
case 5 : return('5');
case 4 : return('4');
case 3 : return('3');
case 2 : return('2');
case 1 : return('1');
case 0 : return('0');
}
return('?'); //return an "F" if if digit is grater than 9
}
void wr_byte(unsigned char d, unsigned char x) //d is the number of digits (leading zeros)
{ //routine writes a 3 position digit for the
char a,b; //byte value "X".
a = x/100; //find the 100's
if (d == 3) putchar(ntoc(a)); //write out ASCII for the 100's
b = x - a*100; //adjust value to the tens
a = b/10; //find the number of 10's
if (d >= 2) putchar(ntoc(a)); //write out the 10's
a = b - a*10; //adjust numbers for one's
putchar(ntoc(a)); //write out the one's
}
void wr_hex(unsigned char x) //hex number with leading zeros
{ //routine writes a 2 position digit for the
unsigned int a; //byte value "X".
a = x/16; //find the number of 16's
putchar(htoc(a)); //write out the 16's
a = x - a*16; //adjust numbers for one's
putchar(htoc(a)); //write out the one's
}
void wr_32hex(unsigned int x) //hex number for 32 bit value
{
unsigned int i; // loop index
unsigned char a;
for (i=4;i>0;i--) { // There is a bug in the compiler... for (i=3;i>=0;i--) doesn't work
a = x >> (8*(i-1)); // get next byte
wr_hex(a); // print ASCII representation of the byte
}
}
unsigned int read_reg(unsigned int x) {
return(x);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -