0% found this document useful (0 votes)
54 views3 pages

Ap.I HYPERTERMINAL FUNCTION PDF

This document describes functions in the <Hyperterm.h> header file for initializing and transmitting data via an EUSART serial port. It initializes the EUSART to run at 19,200 baud, transmits null-terminated strings from RAM or ROM, sends packets of data serially, and receives packets. It also contains functions for converting between binary, BCD, and ASCII representations of numbers.

Uploaded by

Charbel Tadros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views3 pages

Ap.I HYPERTERMINAL FUNCTION PDF

This document describes functions in the <Hyperterm.h> header file for initializing and transmitting data via an EUSART serial port. It initializes the EUSART to run at 19,200 baud, transmits null-terminated strings from RAM or ROM, sends packets of data serially, and receives packets. It also contains functions for converting between binary, BCD, and ASCII representations of numbers.

Uploaded by

Charbel Tadros
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

APPENDIX I: HYPERTERMINAL FUNCTIONS <Hyperterff .

h>

Initialize the EUSART to run at'19?00 baud.


v*id InitUART(v*id) // {JAI1T {TXl?X) run: ;t lS j 3S*,,,baud
t
ANSE LCbJ.ts . ANSC6 a; f / TY, digit*t pi*t'-.,,
ANSELCbits.ANSCT ).: B; // RX digital pin
TXSTAbits.TXEN = 1. ! / transrnLt cnahle
RCSTAbits. CREN
TxSTAbits.BRGH
=
=
7.;
L;
ji ;[;':;.il-ffi;
!I l9 r?*B',*,aud @ 4}1ii;
RCSTAbits.SPEN = 1. /r enable Li&RT
)
Transmit nullrterminaled,:Stiins in RAM {data soace) via the EUSART
void TxRamStr (ehar xstr)

whiJ.e ( lPIRlbits.TxIF) j
TXREG ='*5tn++; 'i.,/1 s*r€* *ze byt* t* be sent
1
Tian<*ii.,r*l+rminated strine,inR0 t f"urosfamrsoace) via the EUSART
vaid TiRomStr(ROM *Str)
t
r+hile (+Str l= '\O') l/ i{ "'10" is Bftco*iltered exit L*i7

uitrile ( I PIRlbits.TXIF);
TXREG = *Str++j I / serialize byte ls be sent

Send data racketseriallv via the,E'IjSAR[


yaid TxPacket,(,ehar *Fatket; ilnsigR*d... :: Len) :.':::: .

far (i ;=4' i < Lan; .i++) :.:,,::.=::,: :.::,::::

{
whlle ( I PIRlbits.TXIr);
TXREG = *Packet+i; I / s*r:-e .l i zr byte to L:e senr
J
]
Receive data oacket sedallv via.thC,EUSART
void RxPacket(char *Packet, unsigned char Len)
t
unsigned char i;

/ 't*ait until *h;lnatt*r i* rer*iv*tj


L

t,,rlri1e ( !PrRl-bits,;'R(IF] j ...,,.,,:,::,:,: I


xPacl<et++ = RCREGj ,/l tt*,'e rrreiu*d d*t* r* rac!<rt['
J

432
eon*ert S-bit N to ASCII chaircteis mexdicits) and store in airav,a fstarlins:with MSD),
v*id .Byte2Asc(unsigr*dr1:a:har N;::oe1fup xs; -, .1....,,., , ,

a[1] = N & 6xOF; ,/l least signi{zcanr dtptL


a[a] += (rtal < 10? '8': 'A' - 10); ll converr MSD ro ,&SCrr
a[1] += (a[1] < 1A? 'E': 'A' - 1A); il coilvert LSD to AS(fI
)
ConVert 16-b'it N to ASCII ch'*@teis,(hex digits) and stoi€-j,n,a-f.,i-ai--a.{startih:Erwith MSD).
void lnlond2Asc{ unsign**=.i.. Nr ,,t,h*,t" ,*a}, ., , : :'ii:r:,:.,:1 ,: -. '',,,
{
unsigned char i, digit;
.: . :t :t:t:

{
digit = lt % 16; = i-Co c{ ll digit rr:
r :.' : N,= N 1 16;,., ,.,.,-. ,:,::::::, f ng${ffif*,L58 Of l{
=.:;,,:::; ,/
.:, ,

digit += (digit < L0? '8': 'A' - 1A); ll r*nver"t di.Eit to &5(II
a[3-i] = digit; 1l \1\* nn tsp talal], t-lil a. alll
l
1'
Convert BCD arrav-of.lensth Len to ASCII'
uojd Bcd2Asc(ihar *a, unsigned char Len)

unsl"€ned chan 1:

for (i = O; i < Len; i++)


a[i] += 'a'; il r*nvert l0 ASCII
l
Convert ASCII ariav'of leasth LenitoBCD.
uoid, A,sc,2Bcd(rhar ,*a; unsi€*-cd char l-en)' 'i
JI I t:t:
i;
urTsigrred chan
tor (i = Aj i < Len; i++)
a[i] &= 0x0F; ll r*nverl La H{*
t

Convert from paCked BCD to 2 bytes of consecutive ASCII characters. Most sienificant first.
rr*id PBCD?Asc(unsigned char SrcRegr char *DstAnr)
(

*DstArn++ = (SacReg y>, ,)..,[ 'a'; / I uw*r n,:Ii:ble t*:,r&5lII


*DstArr-' * (SncReg,,& 6x-0 , t 'B'; t / l*w*r nf,rlbLe t*.:,&5CI1
)
Convert 3-dieit ASCII array to o'iaarv.
unsignecl int: As:c2Bin{char'' *a) ,,,,,, ,

{
r*trJrn (int) (a[A] & 0x6F) * 1OA,::+ (.al1l &'@xoF) 1A +
(a[2] & 6xaF);
Convert 4-digit ASCI I array to binary
unsignerl int Asc2BinE(ehar *a)
{
return (int) (a[8] & AxOF) * 1"OOO + (a,[]-l & 0x0F) * 180: +
(a[2] & 0x0F) x 1o + (a[3] & axoF);
L

+)J
Conve-i1:8-bit N to As€+I.ahais and store in.array a (MSD{rsO
vaid Bin2Asc(unsigned char N, char *a)
{
al2l = (N % 1A) +'*'.; /i ledrl significant di.git
N=N/10j
a[1] = (N % 1"0) + 'A':' /l middle r3gm:frcant rlrgrt
alOT = (N / 1A) + 'e' j /1 nr*st sf gnif lcarrt digit
Conv-#ff'bit N to ASCII chars5d.-sto1e in aiiay a (MSD flrrst)
void Bin2AscE(unsigned 1"nt N, char *a)
t
. : ::ll:

on=ignuo ;;;; i,
ul

-'1;;=;1'l;l-
a[+-i] = (N % rO) + iA';
'= l/ rq:m *f tu I L0 rn ASCII
':::==

Figure I.1: <Flypert*rm " h>

Note: The functions

. void Bcd2Asc(char *a, unsigned ehar Len)


. void Asc28cd(char xa, unsigned ehar Len)
" void PBCD2Asc(unsign*d :ehar SncReg, char *DstArr)
e ilnsigfied int Asc2Bin{char *a)
. unsigned int Asf2BinE(char *a)
. vold Bin2Asc(unsigned char N, char *a)
. void Bin2AscE(unsigned int N, char *a)
are common to the libraries-.<,t{Dx}ib.h>-; l'o o, 8) and <t-typ*rt*rm.h>. In order to avoid
compiler errors when both libraries are used together, the file <tCDxlib.h> has the following
directive on top:

#d*€i.$ ' LcD to r-*rll*v* r*nflitt *ith <i-lyp*rtern:.h>


,,l1
In addition to this, thatiUr*y'iiyperterm " h> uses the following directive:

#ifndef tcD
l l px*r* inpleme*tati*r"r *f ;h*ve {uncti*ns in h*r*
#endif ':'l
This way, if the LCD library is used (LCD defined), then the common functions will not be inserled
twice in the code. These two libraries have been designed carefully so that conflicting functions
appear once.

434

You might also like