研究生
最后登录 1970-1-1
在线时间 小时
注册时间 2016-6-14
1 火花
本帖最后由 lyz864512 于 2016-8-24 09:40 编辑
这是我的程序 请大家指点
#include "stm32f10x.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_exti.h"
#include "stdio.h"
#include "USART.h"
#include "exti.h"
#include "misc.h"
#define ys 0x0fffff//
#define CLI() __set_PRIMASK(1) /* 1رÕ×üÖD¶Ï */
#define SEI() __set_PRIMASK(0) /* ¿a·Å×üÖD¶Ï */
char buf[100];///1003¤¶è
int wei[5];///5λμÄêy×é
int yuwei;///5λêy×éàï±ßêÇ00000
//extern void EXTI_PA0_Config(void);
extern void NVIC_Configuration(void);
extern void GPIO_Configuration1(void);//¶Ë¿ú3õê¼»ˉ
extern void GPIO_Configuration2(void);//¶Ë¿ú3õê¼»ˉ
//long int x;
long int nongdu;///3¤ààDíμÄŨ¶è
//long int yuzhi;
//int flag=4;
void Delay(__IO uint32_t nCount);//¶¨òåÑó3ùoˉêy
void quwei(int shu,int ge[4]);//
//void quwei2(int shu,int ge[4]);//
int main(void)
{
// NVIC_Configuration();
RCC_Configuration();//ê±Öó3õê¼»ˉ
GPIO_Configuration1();//¶Ë¿ú3õê¼»ˉ
GPIO_Configuration2();//¶Ë¿ú3õê¼»ˉ
USART_ClearFlag(USART1, USART_FLAG_TC);//Çå3y±ê־λ
USART2_Config(115200);//′®¿ú13õê¼»ˉ
USART_ClearFlag(USART2, USART_FLAG_TC);//Çå3y±ê־λ
CLI();//Ïè1رÕÖD¶Ï
SEI();// Ôù′ò¿aÖD¶Ï
// EXTI_PA0_Config();//PA0
// EXTI_PC13_Config(); //PC13
//
// nongdu=11520;
while(1)
{
// for(x=00000;x<99999;x++)
// nongdu=x;
// nongdu=yuwei;
//{
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
// nongdu==USART_ReceiveData(USART1);
nongdu=USART1->DR;
//}
quwei(nongdu,wei);
sprintf(buf," IC(550,200,%d) IC(450,200,%d) IC(350,200,%d) IC(250,200,%d) IC(150,200,%d);\r\n",wei[0],wei[1],wei[2],wei[3],wei[4]);
GpuSend(buf);///ÏÔê¾·¢Ëí×ÖÄ£í¼Æ¬
Delay(ys);//
// sprintf(buf,"DS32(480,370,'%d',0);DS32(460,370,'%d',0);DS32(440,370,'%d',0);DS32(420,370,'%d',0);DS32(400,370,'%d',0);\r\n",yuwei[0],yuwei[1],yuwei[2],yuwei[3],yuwei[4]);
// GpuSend(buf);//ÏÔê¾×Ö
//
// yuzhi=yuwei[4]*10000+yuwei[3]*1000+yuwei[2]*100+yuwei[1]*10+yuwei[0];
// if(yuzhi<nongdu)
// GPIO_ResetBits(GPIOF, GPIO_Pin_7);
// else
// GPIO_SetBits(GPIOF, GPIO_Pin_7);
}
}////±è½Ï′óD¡2¢¿ØÖÆled
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
void quwei(int shu,int ge[4])//í¼Æ¬ÏÔê¾×¨óà è¡3öêy×Ö¸÷λ
{
int i;
for(i=0;i!=5;i++)
{
if(shu%10!=0)///%Çóóàêy
ge=shu%10;
else
ge=10;
shu=shu/10;///ÇóéìÕûêy
}
}
//void USART1_IRQHandler(void)
//{
// //????
// if(USART_GetITStatus(USART1,USART_IT_RXNE)==SET)
// {
// USART_ClearITPendingBit(USART1,USART_IT_RXNE);
// nongdu=USART_ReceiveData(USART1);
// quwei(nongdu,wei);
// sprintf(buf," IC(550,200,%d) IC(450,200,%d) IC(350,200,%d) IC(250,200,%d) IC(150,200,%d);\r\n",wei[0],wei[1],wei[2],wei[3],wei[4]);
// GpuSend(buf);///ÏÔê¾·¢Ëí×ÖÄ£í¼Æ¬
////USART_SendData(USART2,buf[]);
// }
// }
void quwei2(int shu,int ge[4])//ÆÕí¨×Ö·û
{
int i=0;
for(i=0;i!=5;i++)
{
ge=shu%10;
shu=shu/10;
}
}
#include "usart.h"
void GPIO_Configuration1(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//3õê¼»ˉËù¶è
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//USART1 TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//¸′óÃíÆíìêä3ö
GPIO_Init(GPIOA, &GPIO_InitStructure);
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//USART RX
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿Õêäèë
// GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void GPIO_Configuration2(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* USART1 GPIO config */
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART1 mode config */
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
/* ê1Äü′®¿ú1½óêÕÖD¶Ï */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//void GPIO_Configuration2(void)
//{
// GPIO_InitTypeDef GPIO_InitStructure;
//
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//3õê¼»ˉËù¶è
//
//// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//USART1 TX
//// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//¸′óÃíÆíìêä3ö
//// GPIO_Init(GPIOA, &GPIO_InitStructure);
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//USART RX
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿Õêäèë
// GPIO_Init(GPIOA, &GPIO_InitStructure);
//}
//void USART1_Config(uint32_t bod)
//{
//
// USART_InitTypeDef USART_InitStructure;
// USART_InitStructure.USART_BaudRate = bod;
// USART_InitStructure.USART_WordLength = USART_WordLength_8b;
// USART_InitStructure.USART_StopBits = USART_StopBits_1;
// USART_InitStructure.USART_Parity = USART_Parity_No ;
// USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
// USART_InitStructure.USART_Mode = USART_Mode_Rx ;
//
// USART_Init(USART1, &USART_InitStructure);
// USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
// USART_Cmd(USART1, ENABLE);
//// USART_Cmd(USART1, ENABLE);
//}
void USART2_Config(uint32_t bod)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = bod;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
USART_Cmd(USART2, ENABLE);
// USART_Cmd(USART1, ENABLE);
}
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOF, ENABLE);
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
}
void GpuSend(char * buf1)
{
int i=0;
while(1)
{
if(buf1!=0)
{
USART_SendData(USART2,buf1);
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
i++;
//
}
else return;
}
}
//int fgetc(FILE *f)
//{
// /* μè′y′®¿ú1êäèëêy¾Y */
// while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
// return (int)USART_ReceiveData(USART1);
//}
//void GpuSend(char * buf1)
//{
// int i=0;
// while(1)
// {
// if(buf1!=0)
// {
// USART_SendData(USART1,buf1);
// while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
// i++;
////
// }
// else return;
// }
//}
我来回答