www.pudn.com > TCPmodbushy.rar > NORMAL.H
/******************************************************************************
* Module Name : NORMAL.H
* CPU Type : 89C51
*
* Description : 通用定义
*
* History Author Version Comment
* 1999.03.15 ZJY V0.1 Original version
*
* Copyright (C) 2003 Xinje Electronic Co., Ltd. All rights reserved.
******************************************************************************/
#ifndef NORMAL_H_DEFINED
#define NORMAL_H_DEFINED
#include "c8051F340.h"
/******************************************************************************
* 用途: 对常用的、普适性的宏的定义
******************************************************************************/
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define int8 signed char
#define INT16S signed short
#define OK 1
#define ERR 0
#define ON 0xFF
#define OFF 0
#define YES 1
#define NO 0
#define TRUE 1
#define FALSE 0
#define LOGIC_POSITIVE TRUE
#define LOGIC_NEGATIVE FALSE
#define RADIX10 10
#define RADIX16 16
#define CHAR_WIDTH 8
#define Bytes_Per_Word 2
#define BitsPerWord ( CHAR_WIDTH * Bytes_Per_Word )
//#define LowLevel OFF
//#define HighLevel ON
/******************************************************************************
* number define for numeral
******************************************************************************/
// 0 - 15 for 0..9 & A..F
#define SpaceNum 16
#define MinusNum 17
#define PlusNum 18
#define PointNum 19
#define StarNum 20
#ifdef need_7Seg_LED
/******************************************************************************
* 7 SEG DEFINE
******************************************************************************/
/*-----------------------------------------------------------------------
;
; 7 SEG and 8th bit ( point ) DEFINE
;
; a
; -------
; | | 7 0
; f | | b +---+---+---+---+---+---+---+---+
; | | | p | g | f | e | d | c | b | a |
; ------- +---+---+---+---+---+---+---+---+
; | g |
; e | | c
; | |
; ------- :: point
; d
;
;-----------------------------------------------------------------------*/
#define SEG_a 0
#define SEG_b 1
#define SEG_c 2
#define SEG_d 3
#define SEG_e 4
#define SEG_f 5
#define SEG_g 6
#define SEG_point 7
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pgfedcba */
#define SEG_Code_NULL 0x00 /* 00000000b ' ' */
#define SEG_Code_0 0x3F /* 00111111b '0' */
#define SEG_Code_1 0x06 /* 00000110b '1' */
#define SEG_Code_2 0x5B /* 01011011b '2' */
#define SEG_Code_3 0x4F /* 01001111b '3' */
#define SEG_Code_4 0x66 /* 01100110b '4' */
#define SEG_Code_5 0x6D /* 01101101b '5' */
#define SEG_Code_6 0x7D /* 01111101b '6' */
#define SEG_Code_7 0x27 /* 00100111b '7' */
#define SEG_Code_8 0x7F /* 01111111b '8' */
#define SEG_Code_9 0x67 /* 01100111b '9' */
#define SEG_Code_A 0x77 /* 01110111b 'A' */
#define SEG_Code_b 0x7C /* 01111100b 'b' */
#define SEG_Code_C 0x39 /* 00111001b 'C' */
#define SEG_Code_d 0x5E /* 01011110b 'd' */
#define SEG_Code_E 0x79 /* 01111001b 'E' */
#define SEG_Code_F 0x71 /* 01110001b 'F' */
#define SEG_Code_i 0x10 /* 00010000b */
#define SEG_Code_L 0x38 /* 00111000b */
#define SEG_Code_n 0x54 /* 01010100b */
#define SEG_Code_o 0x5C /* 01011100b */
#define SEG_Code_P 0x73 /* 01110011b */
#define SEG_Code_r 0x70 /* 01110000b */
#define SEG_Code_S SEG_Code_5 /* 0x6D */
#define SEG_Code_T 0x31 /* 00110001b */
#define SEG_Code_U 0x3E /* 00111110b */
#define SEG_Code_V SEG_Code_U /* 0x3E */
#define SEG_Code_y 0x6E /* 01101110b */
#define SEG_Code_Minus 0x40 /* 01000000b '-' */
#endif
/******************************************************************************
*
******************************************************************************/
#define LowChar( byte ) ( tochar( ( byte ) & 0x0f ) )
#define HighChar( byte ) ( tochar( ( byte ) >> 4 ) )
#define CharToByte( ch, cl ) ( ( uchar ) ( toint( ch ) << 4 ) | ( uchar ) ( toint( cl ) ) )
#define LOW_BYTE( word ) ( ( unsigned char ) ( word ) )
#define HIGH_BYTE( word ) ( ( uchar ) ( ( word ) >> 8 ) )
#define MAKE_WORD( high, low ) ( ( ( uint ) ( high ) << 8 ) | ( uint ) ( low ) )
#define LOW_WORD( DWORD ) ( ( uint ) ( DWORD ) )
#define HIGH_WORD( DWORD ) ( ( uint ) ( ( DWORD ) >> 16 ) )
#define MAKE_LONG( high, low ) ( ( ( ulong ) ( high ) << 16 ) | ( ulong ) ( low ) )
/******************************************************************************
* communication
******************************************************************************/
typedef enum { BaudRate300, BaudRate600, BaudRate1200, BaudRate2400, BaudRate4800, BaudRate9600, BaudRate19200, BaudRate28800, BaudRate38400, BaudRate57600 } BaudRateType;
typedef enum { ParityNone, ParityOdd, ParityEven } ParityType;
typedef enum { DataBits_8, DataBits_7 } DataBitsType;
typedef enum { StopBits_2, StopBits_1 } StopBitsType;
#define NUL 0x00
#define SOH 0x01
#define STX 0x02
#define ETX 0x03
#define EOT 0x04
#define ENQ 0x05
#define ACK 0x06
#define LF 0x0A
#define CR 0x0D
#define NAK 0x15
#define ETB 0x17
#define ESC 0x1B
/******************************************************************************
* Timer
******************************************************************************/
#define Timer0Val ( -1 * ( Timer0Cycle * ( OscFreq / 12 ) / 1000 ) )
// value of timer1 for communication BPS
/*--------------------------------------------------------------*/
/* 波特率 = ( 2 ^ SMOD ) * fosc / [ 32 * 12 * ( 256 - TL1 ) ] */
/*--------------------------------------------------------------*/
#define TL1Val( BR, SMOD ) ( -1 * ( ( 1 << ( SMOD ) ) * ( OscFreq / 12 ) / 32 / ( BR ) ) )
#define TL1Val_BR300 TL1Val( 300, 0 )
#define TL1Val_BR600 TL1Val( 600, 0 )
#define TL1Val_BR1200 TL1Val( 1200, 0 )
#define TL1Val_BR2400 TL1Val( 2400, 0 )
#define TL1Val_BR4800 TL1Val( 4800, 0 )
#define TL1Val_BR9600 TL1Val( 9600, 0 )
#define TL1Val_BR19200 TL1Val( 19200, 1 )
#define TL1Val_BR28800 TL1Val( 28800, 1 )
#define TL1Val_BR38400 TL1Val( 38400, 1 )
#define TL1Val_BR57600 TL1Val( 57600, 1 )
/******************************************************************************
* bit of port 的定义
******************************************************************************/
sbit P0_0 = P0 ^ 0;
sbit P0_1 = P0 ^ 1;
sbit P0_2 = P0 ^ 2;
sbit P0_3 = P0 ^ 3;
sbit P0_4 = P0 ^ 4;
sbit P0_5 = P0 ^ 5;
sbit P0_6 = P0 ^ 6;
sbit P0_7 = P0 ^ 7;
sbit P1_0 = P1 ^ 0;
sbit P1_1 = P1 ^ 1;
sbit P1_2 = P1 ^ 2;
sbit P1_3 = P1 ^ 3;
sbit P1_4 = P1 ^ 4;
sbit P1_5 = P1 ^ 5;
sbit P1_6 = P1 ^ 6;
sbit P1_7 = P1 ^ 7;
sbit P2_0 = P2 ^ 0;
sbit P2_1 = P2 ^ 1;
sbit P2_2 = P2 ^ 2;
sbit P2_3 = P2 ^ 3;
sbit P2_4 = P2 ^ 4;
sbit P2_5 = P2 ^ 5;
sbit P2_6 = P2 ^ 6;
sbit P2_7 = P2 ^ 7;
sbit P3_0 = P3 ^ 0;
sbit P3_1 = P3 ^ 1;
sbit P3_2 = P3 ^ 2;
sbit P3_3 = P3 ^ 3;
sbit P3_4 = P3 ^ 4;
sbit P3_5 = P3 ^ 5;
sbit P3_6 = P3 ^ 6;
sbit P3_7 = P3 ^ 7;
/******************************************************************************
*
******************************************************************************/
#endif