历史上的今天
今天是:2024年11月13日(星期三)
2019年11月13日 | 单片机数控云台master 仿真及源程序
2019-11-13 来源:51hei

源程序:
/*********************************************
This program was produced by the
CodeWizardAVR V1.23.8c Standard
Automatic Program Generator
?Copyright 1998-2003 HP InfoTech s.r.l.
http://www.hpinfotech.ro
e-mail:office@hpinfotech.ro
Project : SKYT
Version : 0.01
Date : 2006-12-6
Author : hlchen
Company :
Comments:
数控云台
Chip type : ATmega8
Program type : Application
Clock frequency : 3.690000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*********************************************/
typedef unsigned char uchar;
typedef unsigned int uint;
#include #include #include "macro.h" #include "LCD.h" //#include "sed1565_s.h" #define RXB8 1 #define TXB8 0 #define UPE 2 #define OVR 3 #define FE 4 #define UDRE 5 #define RXC 7 #define Light 5 #define FRAMING_ERROR (1< // USART Receiver buffer #define RX_BUFFER_SIZE 8 char rx_buffer[RX_BUFFER_SIZE]; unsigned char rx_wr_index,rx_rd_index,rx_counter; // This flag is set on USART Receiver buffer overflow bit rx_buffer_overflow,b_ComEnable; uchar uc_syssta; // USART Receiver interrupt service routine #pragma savereg- interrupt [USART_RXC] void uart_rx_isr(void) { char status,data; #asm push r26 push r27 push r30 push r31 in r26,sreg push r26 #endasm status=UCSRA; data=UDR; if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0) { rx_buffer[rx_wr_index]=data; if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0; if (++rx_counter == RX_BUFFER_SIZE) { rx_counter=0; rx_buffer_overflow=1; }; }; if ((rx_buffer[0]=='o')&&(rx_buffer[1]=='k')) b_ComEnable=1; #asm pop r26 out sreg,r26 pop r31 pop r30 pop r27 pop r26 #endasm } #pragma savereg+ #ifndef _DEBUG_TERMINAL_IO_ // Get a character from the USART Receiver buffer #define _ALTERNATE_GETCHAR_ #pragma used+ char getchar(void) { char data; while (rx_counter==0); data=rx_buffer[rx_rd_index]; if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0; #asm("cli") --rx_counter; #asm("sei") return data; } #pragma used- #endif // USART Transmitter buffer #define TX_BUFFER_SIZE 8 char tx_buffer[TX_BUFFER_SIZE]; unsigned char tx_wr_index,tx_rd_index,tx_counter; // USART Transmitter interrupt service routine #pragma savereg- interrupt [USART_TXC] void uart_tx_isr(void) { #asm push r26 push r27 push r30 push r31 in r26,sreg push r26 #endasm if (tx_counter) { --tx_counter; UDR=tx_buffer[tx_rd_index]; if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0; }; #asm pop r26 out sreg,r26 pop r31 pop r30 pop r27 pop r26 #endasm } #pragma savereg+ #ifndef _DEBUG_TERMINAL_IO_ // Write a character to the USART Transmitter buffer #define _ALTERNATE_PUTCHAR_ #pragma used+ void putchar(char c) { while (tx_counter == TX_BUFFER_SIZE); #asm("cli") if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0)) { tx_buffer[tx_wr_index]=c; if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0; ++tx_counter; } else UDR=c; #asm("sei") } #pragma used- #endif // Standard Input/Output functions #include uchar ucInputValue; uint uiLastADValue[3]; uchar ucInputParam0; uchar ucChannelN,uc_ReceiveSta; bit bInputChange,bMotorSpeed,bLight,bReceiveOpend; void inputdeal(void); void TransmitEnable(void); void ReceiveEnable(void); void Communication(void); void LcdShow(void); #define HighSpeed 0x33 #define SlowSpeed 0x99 #define ADC_VREF_TYPE 0x00 #define RE 0 #define DE 1 // ADC interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) { // Place your code here TCNT0=0xf0; } interrupt [ADC_INT] void adc_isr(void) { uint adc_data; // Read the AD conversion result adc_data=ADCW; // Place your code here switch (ucChannelN) { case 0: if (uiLastADValue[0]!=adc_data) { uiLastADValue[0]=adc_data; ucInputParam0=uiLastADValue[0]*24/1024; //ucInputParam0 = tmp/100; //ucInputParam1 = (tmp%100)/10; //ucInputParam2 = (tmp%100)%10; bInputChange=1; ucInputValue=0x01; } ADMUX=0x01; break; case 1: if (uiLastADValue[1]!=adc_data) { uiLastADValue[1]=adc_data; ucInputParam0=uiLastADValue[1]*12/1024; //ucInputParam0 = tmp/100; //ucInputParam1 = (tmp%100)/10; //ucInputParam2 = (tmp%100)%10; bInputChange=1; ucInputValue=0x02; } ADMUX=0x02; break; case 2: if (uiLastADValue[2]!=adc_data) { uiLastADValue[2]=adc_data; //ucInputParam0=uiLastADValue[2]*6/1024; if (abs(uiLastADValue[2]-1023)<100) ucInputValue=3; else if (abs(uiLastADValue[2]-465)<50) ucInputValue=4; else if (abs(uiLastADValue[2]-292)<25) ucInputValue=5; else if (abs(uiLastADValue[2]-204)<25) ucInputValue=6; else if (abs(uiLastADValue[2]-146)<12) ucInputValue=7; else if (abs(uiLastADValue[2]-93)<12) ucInputValue=8; else if (abs(uiLastADValue[2])<6) ucInputValue=9; else break; // else if (abs(uiLastADValue[2]-512 //ucInputParam0 = tmp/100; //ucInputParam1 = (tmp%100)/10; //ucInputParam2 = (tmp%100)%10; bInputChange=1; // ucInputValue=ucInputParam0+2; } ADMUX=0x00; break; default: break;
史海拾趣
|
分别用C语言和汇编语言进行程序设计,计算正弦函数值,并比较代码效率。 1)C语言编程 #include #define NX 180 //最大正弦角度 #define pi 3.14159 short i; double x[NX] //定义输入正弦角度数组(弧度值) double r[NX] //定义输出 ...… 查看全部问答> |
|
wice/mobile 5.0,6.0 qq群37371845 帮顶有分 从事wince和mobile程序开发一段时间,一直没有发现比较好的交流技术群,希望大家一起来讨论学习~ 开发平台:vs2005/vs2008 开发语言:C# 有兴趣的可以一起讨论~… 查看全部问答> |
|
流小驱动SRB.NumberOfPhysicalPages时钟为0 修改DDK中testcap 做的摄像头驱动,想使用DMA得到数据。DDK文档中说SRB的ScatterGatherBuffer就是作为DMA使用的,NumberOfPhysicalPages是其中的元素个数。但是我在生成图像的ImageSynth函数中得到的NumberOfPhysicalPages却始终为0. ...… 查看全部问答> |
|
利用控制面板中的“校准”,校准后总是不能正常退出。串口打印提示 : M 474,507 507,520 33,13M 2061,1655 2099,1655 38,0Maximum Allowed Error 7: Maximum error 13325 exceeds calibration th ...… 查看全部问答> |
|
本帖最后由 jameswangsynnex 于 2015-3-3 19:57 编辑 苹果公司的iPhone把智能手机从专注于通讯的设备变成了以应用为中心的多用途移动平台,可以用于许多产业之中。据iSuppli公司,其它智能手机平台迅速跟进,纷纷增加了多点触控用户界面、应用开发 ...… 查看全部问答> |
|
关于C3版的9B96等的FLASH擦写次数 根据官方给出的最新版本勘误表,对于C3 和C5版本的芯片 FLASH 最大擦写次数为100次,最好还是在SRAM里调程序,而不要烧到FLASH里去,确实调试过程中烧写是之前常用的方法,即使是产品,这个问题有待TI去解决吧 ...… 查看全部问答> |
|
本人刚开始学习嵌入式linux,手头上有一块周立功的smartarm2400开发板,处理器是arm7tdmi。 在网上搜了很多资料,有的说不支持mmu只能移植μclinux,有的说现在的版本的linux已经可以支持,很迷惘。 另外想请教下学习linux(或者μclinux)有什么 ...… 查看全部问答> |




