Hardware Reference
In-Depth Information
Prototype
Function
Category: time delay
void delay by 10 us (int k);
void delay by 50 us (int k);
void delay by 1 ms (int k);
void delay by 10 ms (int k);
void delay by 100 ms (int k);
void delay by 1 s(int k);
Creates a time delay that is equal to 10 k us
Creates a time delay that is equal to 50 k us
Creates a time delay that is equal to k ms
Creates a time delay that is equal to 10 k ms
Creates a time delay that is equal to 100 k ms
Creates a time delay that is equal to k sec
Category: terminal I/O
int putch(char cx);
int puts(const char *cptr);
int newline(void);
int putsr(char *cptr);
char getch (void);
int gets(char *ptr);
Outputs the character cx to the sci0 port
Outputs the string pointed to by cptr to the sci0 port
Outputs a carriage return followed by a linefeed
Outputs a string stored in SRAM that is pointed to by cptr
Reads a character from the sci0 port using polling method
Reads a string terminated by a carriage return and saves
it in a buffer pointed to by ptr
Category: Data conversion
int int2alpha(int xx, char arr[]);
Converts the 16-bit integer xx into a decimal string and
stores it in an array arr[]
Converts the 32-bit integer xx into a decimal string and
stores it in an array arr[]
Converts the ASCII string pointed to by ptr into a 16-bit
binary number
Converts the ASCII string pointed to by ptr into a 32-bit
binary number
Reverses a string that is stored in the character array with
k characters and its sign is indicated by sign
int long2alpha(long xx, char arr[]);
int alpha2int(char *ptr);
long alpha2long(char *ptr);
int reverse(char arr[], int k,
char sign);
Table E.1 Library functions for EGNU IDE
Example E.1
Write a program to convert a 32-bit integer to a string and then output it to the SCI0 port.
Solution: The program is as follows:
#include “c:\egnu\include\hcs12.h”
#include “c:\egnu\include\convert.c”
#include “c:\egnu\include\stdio.c”
const char *msg 1 “Prepare to convert!\n”;
int main(void)
{
long temp;
char buf[20];
/* used to hold the converted ASCII string */
temp 5 993450123;
/* number to be converted */
puts(msg);
/* output a message */
newline();
/* move to the beginning of the next line */
Search WWH ::




Custom Search