/*
================================================================================
* Copyright(c) YiheTech studio, All rights reserved
* File Name : main.c
* Author : LiYong
* Date : 2009-6-8 20:36:46
* Version : V1.0
* Description : Demo program
* Target Device: C8051F330
* Compiler : KeilC51V8.16
* Note : None
================================================================================
*/
#include "C8051F320.h"
#include "mytypedef.h"
/*
================================================================================
----------------------------Internal static functions---------------------------
================================================================================
*/
/*Initialize the system clock */
static void ClockInit( void );
/*Initialize timer3, 1ms overflow*/
static void Timer3Init( void );
/*Initialize the GPIOs*/
static void GPIOInit( void );
/*Delay for some times*/
static void Delay10Ms( unsigned char dly );
/*Initialize the UART0*/
static UART0_Init( void );
/*Initialize the timer1 for baudrate*/
void Timer1_Init( void );
/*Send a byte via the UART0*/
static void UART_Send( INT8U dt );
/*Send a byte via the UART0*/
static void UART_SendArray( INT8U *buff, INT8U size );
/*
================================================================================
----------------------------Internal static variables---------------------------
================================================================================
*/
static volatile INT8U Counter_10ms = 0;
//static volatile INT8U UART_RecBuffer[110];
//static volatile INT8U UART_SendBuffer[55];
static volatile INT8U UART_Timeout = 0;
static volatile INT8U UART_RecCount = 0;
unsigned char rxd_buffer_locked =0;
unsigned char rx_tmp=0;
//unsigned char idata UART_SendBuffer[110];
unsigned char xdata UART_RecBuffer[150];
unsigned char xdata UART_SendBuffer[150];
/*
================================================================================
* Name : ClockInit( )
* Description : Initialize the system clock
* Input : None
* Output : None
* Note : None
================================================================================
*/
static void ClockInit( void )
{
PCA0MD &= ~0x40;
OSCICN |= 0x83;
RSTSRC = 0x04; //system clocm : internal H-F
}
/*
================================================================================
* Name : Timer3Init( )
* Description : Initialize timer3, 10ms overflow
* Input : None
* Output : None
* Note : None
================================================================================
*/
static void Timer3Init( void )
{
TMR3RLH = 0xbe;
TMR3RLL = 0x00;
TMR3H = 0xbe;
TMR3L = 0x00;
TMR3CN = 0x04;
EIE1 |= ( 1<<7 );
}
/*
================================================================================
* Name : Timer3_ISR( )
* Description : Interrupt service routine for timer3
* Input : None
* Output : None
* Note : None
================================================================================
*/
static Timer3_ISR( void ) interrupt 14
{
TMR3CN &= ~( 1<<7 );
Counter_10ms ++;
++UART_Timeout;
}
/*
================================================================================
* Name : Delay10Ms( )
* Description : Delay for some times
* Input : None
* Output : None
* Note : None
================================================================================
*/
/*
static void Delay10Ms( unsigned char dly )
{
while( dly-- )
{
Counter_10ms = 0;
while( Counter_10ms == 0 );
}
}
*/
/*
================================================================================
* Name : GPIOInit( )
* Description : Initialize the GPIOs
* Input : None
* Output : None
* Note : None
================================================================================
*/
static void GPIOInit( void )
{
P0SKIP = 0x0F;
XBR0 = 0x01;
XBR1 = 0x40;
}
/*
================================================================================
* Name : Timer1_Init( )
* Description : Initialize the timer1 for baudrate
* Input : None
* Output : None
* Note : None
================================================================================
*///38400 =64,,57600=98
void Timer1_Init( void )
{
TH1 = 0x98;
TL1 = 0x98;
TCON &= 0x3f;
TMOD &= 0x0F; //装初值
TMOD |= ( 2<<4 ); //装初值
CKCON |= 0x01 | ( 1<<3 );
TCON |= ( 1<<6 );
}
/*
================================================================================
* Name : UART0_Init( )
* Description : Initialize the UART0, baudrate : 38400
* Input : None
* Output : None
* Note : None
================================================================================
*/
static UART0_Init( void )
{
SCON0 = ( 1<<4 );
IE |= ( 1<<4 );
P0MDOUT |= ( 1<<4 );
Timer1_Init( );
}
/*
================================================================================
* Name : UART0_ISR( )
* Description : Interrupt service routine for UART0
* Input : None
* Output : None
* Note : None
================================================================================
*/
static INT8U *SendPtr = NULL;
static INT8U SendCount = 0;
static UART0_ISR( void ) interrupt 4
{
INT8U i;
if( SCON0 & ( 1<<1 ) )
{
//TX ok
SCON0 &= ~( 1<<1 );
if( SendCount )
{
i = *SendPtr ++;
SBUF0 = i;
SendCount--;
}
}
else if( SCON0 & ( 1<<0 ) )
{
//RX ok
UART_Timeout = 0;
SCON0 &= ~( 1<<0 );
i = SBUF0;
if( UART_RecCount != 255 )
{
UART_RecBuffer[UART_RecCount] = i;
UART_RecCount ++;
}
}
}
/*
================================================================================
* Name : UART_Send( )
* Description : Send a byte via the UART0
* Input : -dt, The byte to be sent
* Output : None
* Note : None
================================================================================
*/
/*
static void UART_Send( INT8U dt )
{
SendPtr = &dt;
SendCount = 1;
SCON0 |= ( 1<<1 );
while( SendCount != 0 );
}
*/
/*
================================================================================
* Name : UART_Send( )
* Description : Send a byte via the UART0
* Input : -dt, The byte to be sent
* Output : None
* Note : None
================================================================================
*/
static void UART_SendArray( INT8U *buff, INT8U size )
{
SendPtr = buff;
SendCount = size;
SCON0 |= ( 1<<1 );
while( SendCount != 0 );
}
void DSbase64()
{
//base64解码,数据包前三个是起始位,地址位,命令,不参与编码和解码
//最后三位是两个crc校验位和一个结束符,也不参与编码和解码
unsigned char a,b,c,d;
unsigned char x,y,z;
unsigned char ptrIn = 3;
unsigned char ptrOut = 3;
unsigned short int len=rx_tmp-6;//len应该是4的倍数
unsigned short int p=0;
while(p<len)
{
a = UART_SendBuffer[ptrIn++] - '=';
b = UART_SendBuffer[ptrIn++] - '=';
c = UART_SendBuffer[ptrIn++] - '=';
d = UART_SendBuffer[ptrIn++] - '=';
p=p+4;
x = (a << 2) | (b >> 4);
y = ((b & 0x0f) << 4) | (c >> 2);
z = ((c & 0x03) << 6) | d;
UART_SendBuffer[ptrOut++] = x;
UART_SendBuffer[ptrOut++] = y;
UART_SendBuffer[ptrOut++] = z;
}
}
/*
================================================================================
------------
C8051F320.rar_c8051f320
版权申诉
5星 · 超过95%的资源 165 浏览量
2022-07-13
19:42:24
上传
评论
收藏 43KB RAR 举报
小波思基
- 粉丝: 70
- 资源: 1万+
最新资源
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 2017校招真题校园招聘真题算法题(37道)Python源码.zip
- 基于单片机protues仿真的多功能自动饮水机系统设计(仿真图、源代码、演示视频)
- 二叉树7-1-1.cpp
- android 9.0 原生模拟器 签名文件
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈