?? siodemo.c
字號:
/* SIODEMO.C */
/***************************************************************************
*
* ---------------------------------------------
*Main module for STK16X (ASC0, 57600 Baud, 8, 1, n) demo
*
*
* TQ-Systems GmbH
* ----------------
* Customer: TQ-Components
* Project : STK16XSW
* Tools : uVision 2.05
*
* Copyright (C) 1995 TQ-Systems
* -----------------------------
* Rev: Date: Name: Modification:
* ----+---------+----------------+------------------------------------------
* 100 27.04.01 K. Z鰌f taken over from STK16X.506
/*****************************************************************************/
/************************************************************************/
/****************************************************************************
*
*
* availability summary
*
* available for Starterkit: STK16x STK16XU
* conformed for Starterkit: Stk16x STK16XU
* available for Modul : TQM167UL TQM167U TQM167UE
* TQM164 TQM165 TQM167LC TQM167C
* conformed for Modul : TQM167UL TQM167U TQM167UE
* TQM164 TQM165 TQM167LC TQM167C
*****************************************************************************/
/*--------------------------------------------------------------------------*
* Standard-Include-Files:
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <ctype.h> /* Typecast functions */
#include <string.h> /* String functions */
#include <setjmp.h> /* Global jump functions */
/*--------------------------------------------------------------------------*
* Hardware- and Compiler-spezifische Include-Files:
*---------------------------------------------------------------------------*/
#include <absacc.h> /* absolute accesss */
#include <intrins.h> /* Intrinsic functions */
#include <reg167.h> /* Special function register */
/*--------------------------------------------------------------------------*
*product specific include-files:
*---------------------------------------------------------------------------*/
#include "header.h"
#include "timer.h"
/* control character: */
#define BK 0x03
#define BS 0x08
#define CR 0x0D
#define LF 0x0A
#define XON 0x11
#define XOFF 0x13
/* baudrate definition */
#define BR9600 0
#define BR19200 1
#define BR38400 2
#define BR57600 3
/* appropriated Baudrate */
#define USED_BAUDRATE BR57600
/* control-bits serial interface: */
sbit P3_8 = P3^8;
sbit P3_10 = P3^10;
sbit DP3_8 = DP3^8;
sbit DP3_9 = DP3^9;
sbit DP3_10 = DP3^10;
sbit DP3_11 = DP3^11;
/* to initialize Asynchrone serial Interface ASC0 : */
void initasc()
{
/* Reload-Values for 9600, 19200, 38400 und 57600 Baud: */
const int br[4] = { 0x40, 0x20, 0x0F, 0x0A };
int n; /* Number of Baudrate */
n = USED_BAUDRATE;
/* to initialize data reception over interface: */
P3_10 =1; /* P3.10-Output-Latch (TxD0) enable */
DP3_10 =1; /* P3.10 (TxD0) switch to output */
DP3_11 =0; /* switch RxD0 to input */
S0TIC =0x80; /* Transmit-Interrupt disable */
S0RIC =0x00; /* Receive-Interrupt disable */
S0BG =br[n]; /* initialize Baudrate */
S0CON =0x8011; /* start up Baudrate-Generator , */
/* activate receiving Data , */
/* 8-Datenbits, no Parit鋞sbit */
IEN = 1; /* to enable global Interrupt */
}
/* Test to receive characters : */
/* return: Integer = >0, if receive a character */
int keypressed()
{
int flag;
char ch;
/* read Data : */
flag=S0RIR; /* ASC0-receive-Flag */
ch =S0RBUF; /* receive character */
/* to ignore LF, Xon and Xoff : */
if (flag && (ch==LF || ch==XON || ch==XOFF)) flag=0;
return flag;
}
/* read character : overwrite Standartfunction */
/* return: char = from ASC0 received character */
char _getkey()
{
char ch;
while(!keypressed()); /* wait of character */
ch=S0RBUF; /* read received character */
S0RIR=0; /* to relocate recieve-Flag */
return ch;
}
/* to write out character : overwrite Standardfunction, for example printf verw. */
/* committal: char = character to send */
/* return: char = transmited character */
char putchar (char ch)
{
if (ch=='\n') putchar(13); /* converting LF -> CR+LF */
while (!S0TIR); /* wait until last character is transmited */
S0TIR=0; /* to relocate transmit-Flag */
return (S0TBUF=ch); /* write character to transmit buffer */
}
/* receive a character: */
/* return: char = received character */
/* released character: "0".."9" , "A".."Z" , " " , "," , "=" */
/* converting "a".."z" into "A".."Z" */
char sio_getchar()
{
/* Local variables: */
char c;
while (1)
{
c=_getkey();
/* Testing the received character: */
switch (c)
{
case BS:
case BK:
return c;
case CR:
putchar(c);
return c;
/* Filtering valid characters: */
default:
if (isalnum(c)||(c==' ')||(c==',')||(c=='='))
{
c=toupper(c);
putchar(c);
return c;
}
}
}
return 0;
}
/* wait action: time is in ms, max. 3.3 s */
void delay(unsigned int time)
{
T0R=0; /* Timer 0 Stop */
T0IR=0; /* deletes Interrupt-Request-Flag */
T0=-((((long)time)*5000)/256); /* Timer-Value in 51.2 us */
T01CON=T01CON&0xFF00|(0x40+0x07); /* T0R=1, T0M=0, T0I=3 */
while(!T0IR); /* wait of Timeout */
}
/* arithmetic technique prime number : */
void primzahlen()
{
unsigned long z, t, r;
printf("\n\nPrimzahlen: Abbruch auf Tastendruck.");
z=1; r=1;
while(!keypressed()) /* truncation top press any Key */
{
while(r*r<z) r++;
for(t=3; t<=r; t+=2) if(z%t==0) break;
if(t>r) printf("\n%5li", z);
z+=2;
}
_getkey(); /* read character */
}
/* rolling direction: */
void lauflicht()
{
unsigned int i;
printf("\n\nLauflicht auf Port 2: Abbruch auf Tastendruck.");
if (TQMMOD==TQM164)
{
MVAR(unsigned int, 0xF106) =0xffff; /* set Port P1H to output : */
P1H = 0x0001;
}
else
{
DP2 = 0xFFFF; /* set P2 to output: */
P2 = 0x0101;
}
/* Lauflicht: */
i=0;
while(!keypressed()) /* truncation top press any Key */
{
i+=4;
if(!i)
{
if (TQMMOD==TQM164)
{P1H<<=1; if((P1H&0x00FF)==0) P1H=0x0001; }
else
if (TQMMOD==TQM165)
{P2<<=1; if((P2&0xFF00)==0) P2=0x0101; }
else
{P2<<=1; if((P2&0x00FF)==0) P2=0x0101; }
}
}
/* set back Port P1H to input: */
if (TQMMOD==TQM164) MVAR(unsigned int, 0xF106) =0;
else DP2 = 0; /* set back P2 to input: */
}
/* mainfunktion: */
void main (void)
{
char ch;
initasc(); /* initialize input- und output */
while(1)
{
printf(
"\n\nDemonstrationsprogramm fuer TQM164/165/166/167/167LC: SIODEMO.C"\
"\n\n<P> :Primzahlenberechnung"\
"\n<L> :Lauflicht an Port 2"\
"\n<R> :Reset (TRAP 0)"\
"\n");
do
{
printf("\n>");
putchar(ch=toupper(_getkey()));
switch(ch)
{
case 'P' :primzahlen(); break;
case 'L' :lauflicht(); break;
case 'R' :_trap_(0);
}
}
while(ch>32);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -