欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
程序寫入51單片機后,單片機沒有按照預期運行
[打印本頁]
作者:
小新新000424
時間:
2024-4-3 19:40
標題:
程序寫入51單片機后,單片機沒有按照預期運行
如圖所示,本人使用的江協科技的51單片機,燒錄成功后單片機沒有按照程序運行。蜂鳴器持續響起,LED全亮。
IMG_20240403_154237_edit_7563114578532.jpg
(2.04 MB, 下載次數: 22)
下載附件
2024-4-3 19:35 上傳
本人排查了好久都沒有找到問題,望各位專家解答。
部分代碼如下:
main.c:
#include <REGX52.H>
#include "Delay.h"
#include "ADC0832.h"
#include<stdio.h>
#include "uart.h"
#define uchar unsigned char
#define uint unsigned int
#define false 0
#define true 1
unsigned int AD_X;
unsigned int AD_Y;
//Unicode
char Unicode_latitude[10*latitude_Length]='0';
char Unicode_N_S[10*N_S_Length];
char Unicode_longitude[10*longitude_Length];
char Unicode_E_W[10*E_W_Length];
void errorLog(int num)//解析錯誤
{
while (1)
{
Uart1Sends("ERROR");
Uart1Send(num+0x30);
Uart1Sends("\r\n");
}
}
void parseGpsBuffer()//獲得GPS數據
{
char *subString;
char *subStringNext;
char i = 0;
if (Save_Data.isGetData)
{
Save_Data.isGetData = false;
//Uart1Sends("**************\r\n");
//Uart1Sends(Save_Data.GPS_Buffer);
for (i = 0 ; i <= 6 ; i++)
{
if (i == 0)
{
if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)
errorLog(1); //解析錯誤
}
else
{
subString++;
if ((subStringNext = strstr(subString, ",")) != NULL)
{
char usefullBuffer[2];
switch(i)
{
case 1:memcpy(Save_Data.UTCTime, subString, subStringNext - subString);break; //獲取UTC時間
case 2:memcpy(usefullBuffer, subString, subStringNext - subString);break; //獲取UTC時間
case 3:memcpy(Save_Data.latitude, subString, subStringNext - subString);break; //獲取緯度信息
case 4:memcpy(Save_Data.N_S, subString, subStringNext - subString);break; //獲取N/S
case 5:memcpy(Save_Data.longitude, subString, subStringNext - subString);break; //獲取經度信息
case 6:memcpy(Save_Data.E_W, subString, subStringNext - subString);break; //獲取E/W
default:break;
}
subString = subStringNext;
Save_Data.isParseData = true;
if(usefullBuffer[0] == 'A')
Save_Data.isUsefull = true;
else if(usefullBuffer[0] == 'V')
Save_Data.isUsefull = false;
}
else
{
errorLog(2); //解析錯誤
}
}
}
}
}
/***
void printGpsBuffer()//輸出GPS數據
{
if (Save_Data.isParseData)
{
Save_Data.isParseData = false;
Uart1Sends("Save_Data.UTCTime = ");
Uart1Sends(Save_Data.UTCTime);
Uart1Sends("\r\n");
if(Save_Data.isUsefull)
{
Save_Data.isUsefull = false;
Uart1Sends("Save_Data.latitude = ");
Uart1Sends(Save_Data.latitude);
Uart1Sends("\r\n");
Uart1Sends("Save_Data.N_S = ");
Uart1Sends(Save_Data.N_S);
Uart1Sends("\r\n");
Uart1Sends("Save_Data.longitude = ");
Uart1Sends(Save_Data.longitude);
Uart1Sends("\r\n");
Uart1Sends("Save_Data.E_W = ");
Uart1Sends(Save_Data.E_W);
Uart1Sends("\r\n");
}
else
{
Uart1Sends("GPS DATA is not usefull!\r\n");
}
}
}
***/
//ASCLL-Unicode
void ASCII_TO_Unicode(char *ASCII,char *Unicode)
{
int length;
int i = 0;
int j = 0;
memset(Unicode,'\0',sizeof(Unicode));
length = strlen(ASCII);
for(i=0;i<length;i++)
{
Unicode[j++] = '0';
Unicode[j++] = '0';
Unicode[j++] = (ASCII[i] / 16) + 0x30;
Unicode[j++] = (ASCII[i] % 16) + 0x30;
}
}
void main()
{
Uart_Init();
Delay(10000);
//clrStruct();
while(1)
{
AD_X=ADC0832(1);
AD_Y=ADC0832(0);
parseGpsBuffer();
//ASCII_TO_Unicode(Save_Data.E_W,Unicode_E_W);
//printGpsBuffer();
if((AD_X<=47 || AD_X>=126) || (AD_Y>=141 || AD_Y<=57))
{
//----------------為什么是下面這些AT指令呢,請看群共享文件SIM900A重要的信息指令文件------------
ASCII_TO_Unicode(Save_Data.latitude,Unicode_latitude);
ASCII_TO_Unicode(Save_Data.longitude,Unicode_longitude);
Uart1Sends("AT\r\n");
Delay(2000);//延時大約2秒
//Uart1Sends("AT+CSCS=\"UCS2\"\r\n");
//Delay(2000);//延時大約2秒
Uart1Sends("AT+CMGF=1\r\n");
Delay(2000);//延時2秒
Uart1Sends("AT+CSCA?\n");
Delay(2000);//延時2秒
Uart1Sends("AT+CSMP=17,167,0,25\r\n");
Delay(2000);//延時2秒
//Uart1Sends("AT+CMGS=\"00310039003100360037003500340036003700320034\"\r\n");//此處修改為對方的電話號,電話話的UNICON編碼,可使用我們配套的
//資料包中的 中文轉UNICON編碼工具來獲取。特別注意:那個軟件
//獲得的unicon 編碼待有空格,實際中要去掉,否則模塊會報錯
Uart1Sends("AT+CMGS=\"19167546724\"\r\n");
Delay(2000);//延時2秒
Uart1Sends("4F7F7528800553EF80FD64545012FF0C8BF7524D5F8063075B9A573070B9655152A9FF01");//修改信息內容,內容可為中文、英文和數字,但都是對應的unicon 編碼。
Uart1Sends(Unicode_latitude);
Uart1Sends("004E0053");
Uart1Sends(Unicode_longitude);
Uart1Sends("00450057");
/***
Uart1Sends("使用者可能摔倒,請前往");
Uart1Sends(Save_Data.N_S);
Uart1Sends(Save_Data.latitude);
Uart1Sends(Save_Data.E_W);
Uart1Sends(Save_Data.longitude);
Uart1Sends("進行救助!");
***/
Uart1Send(0x1a);
Delay(8000);//延時10秒
}
Delay(100);
}
}
復制代碼
uart.c:
#include "uart.h"
//以下是開機后發送到手機的內容,發送的號碼在程序中修改。
unsigned int rec_data_len_uart=0; //標記Buffer_Uart0接收數組
unsigned char idata Buffer_Uart0_Rec[25]={0}; //Uart0中斷接收數組
//注意,無論接收到信號還是發送完信號,都會進中斷服務程序的
char idata gpsRxBuffer[gpsRxBufferLength];
unsigned char RX_Count = 0;
_SaveData Save_Data;
void Uart_Init()
{
SCON = 0X50; //UART方式1;8位UART
REN = 1; //允許串行口接收數據
PCON = 0x00; //SMOD=0;波特率不加倍
TMOD = 0x20; //T1方式2,用于產生波特率
TH1 = 0xFD; //裝初值
TL1 = 0xFD;
TR1 = 1; //啟動定時器1
EA = 1; //打開全局中斷控制
ES = 1; //打開串行口中斷
}
void Uart1Sends(unsigned char *p) //·¢?í×?·?′?
{
while(*p)
{
SBUF=*(p++);
while(TI==0)
{
};
TI=0;
}
}
void Uart1Send(unsigned char c) //·¢?íò???×?·?
{
TI=0;
SBUF=c;
while(TI==0);
TI=0;
}
/***
void Serial_interrupt() interrupt 4
{
unsigned char temp_rec_data_uart0;
temp_rec_data_uart0 = SBUF;//讀取接收數據
RI=0;//接收中斷信號清零,表示將繼續接收
Buffer_Uart0_Rec[rec_data_len_uart]=temp_rec_data_uart0; //接收數據
rec_data_len_uart++;
if(rec_data_len_uart>24)
{
rec_data_len_uart=0; //從頭開始接收數據
}
}
***/
/*串行通訊中斷,收發完成將進入該中斷*/
void RECEIVE_DATA(void) interrupt 4 using 3
{
unsigned char temp = 0;
char i = 0;
ES=0;
temp = SBUF;
RI = 0;
if(temp == ')
{
RX_Count = 0;
}
if(RX_Count <= 5)
{
gpsRxBuffer[RX_Count++] = temp;
if(temp == '\n')
{
memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //=?||
memcpy(Save_Data.GPS_Buffer, gpsRxBuffer, RX_Count); // mph||
Save_Data.isGetData = true;
RX_Count = 0;
memset(gpsRxBuffer, 0, gpsRxBufferLength); //??Σ
}
if(RX_Count >= 75)
{
RX_Count = 75;
gpsRxBuffer[RX_Count] = '\0';//ìí?ó?áê?·?
}
}
ES=1;
}
void clrStruct()
{
Save_Data.isGetData = false;
Save_Data.isParseData = false;
Save_Data.isUsefull = false;
memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //清空
memset(Save_Data.UTCTime, 0, UTCTime_Length);
memset(Save_Data.latitude, 0, latitude_Length);
memset(Save_Data.N_S, 0, N_S_Length);
memset(Save_Data.longitude, 0, longitude_Length);
memset(Save_Data.E_W, 0, E_W_Length);
}
復制代碼
uart.h:
/******************************************************************
作者:神秘藏寶室
最終解釋權歸原作者所有,鄙視其他店鋪不勞而獲的抄行為!
******************************************************************/
#ifndef __UART_H__
#define __UART_H__
#include <REGX52.H>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
//定義數組長度
#define GPS_Buffer_Length 80
#define UTCTime_Length 11
#define latitude_Length 11
#define N_S_Length 2
#define longitude_Length 12
#define E_W_Length 2
typedef struct SaveData
{
char GPS_Buffer[GPS_Buffer_Length];
char isGetData; //是否獲取到GPS數據
char isParseData; //是否解析完成
char UTCTime[UTCTime_Length]; //UTC時間
char latitude[latitude_Length]; //緯度
char N_S[N_S_Length]; //N/S
char longitude[longitude_Length]; //經度
char E_W[E_W_Length]; //E/W
char isUsefull; //定位信息是否有效
} xdata _SaveData;
//函數或者變量聲明
extern void Uart_Init();
extern void Uart1Sends(unsigned char *p);
extern void Uart1Send(unsigned char c);
extern void clrStruct();
#define gpsRxBufferLength 76
extern char idata gpsRxBuffer[gpsRxBufferLength];
extern unsigned char RX_Count;
extern _SaveData Save_Data;
extern unsigned int rec_data_len_uart; //標記Buffer_Uart0接收數組
extern unsigned char idata Buffer_Uart0_Rec[25];
#endif
復制代碼
作者:
xiaoyao166ny
時間:
2024-4-4 10:55
生成的少錄文件 完整不
作者:
hx117
時間:
2024-4-4 20:49
估計是燒錄文件不完整吧
作者:
fosu頑童
時間:
2024-4-6 14:16
1-可能是缺少了I/O口配置初始化
2-可能延時函數時間太長,需要等待一段時間才正常
3-單片機芯片可能損壞,建議更換試一下
作者:
wannenggong
時間:
2024-4-6 19:48
使用STC單片機時建議在STC-ISP軟件中下載、使用相關的STC***.h頭文件,可以避免很多奇怪的問題。
作者:
PIZI0515
時間:
2024-4-7 10:40
1-可能是缺少了I/O口配置初始化
2-可能延時函數時間太長,需要等待一段時間才正常
3-單片機芯片可能損壞,建議更換試一下
另外使用STC單片機時建議在STC-ISP軟件中下載、使用相關的STC***.h頭文件,可以避免很多奇怪的問題
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1