⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于三星44B0的步进电机的控制实验原代码
💻 C
字号:
/************************************************\*	by threewater<threewater@up-tech.com>	**		2003.12.18			**						*\***********************************************/#include <stdio.h>#include <unistd.h>#include <linux/delay.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/ioctl.h>#include <pthread.h>#include "hardware.h"#include "motor.h"#include "exio.h"#include "../keyboard/get_key.h"#include <fcntl.h>#include <string.h>#include <sys/ioctl.h>#include "zlg7289.h"#define ADCCON_FLAG		0x40#define ADCCON_SLEEP		0x20#define ADCCON_ADIN0		(0x0<<2)#define ADCCON_ADIN1		(0x1<<2)#define ADCCON_ADIN2		(0x2<<2)#define ADCCON_ADIN3		(0x3<<2)#define ADCCON_ADIN4		(0x4<<2)#define ADCCON_ADIN5		(0x5<<2)#define ADCCON_ADIN6		(0x6<<2)#define ADCCON_ADIN7		(0x7<<2)#define ADCCON_READ_START	0x2#define ADCCON_ENABLE_START	0x1#define ZLG7289_CS				(0x20)	//GPB5#define ZLG7289_KEY                             (0x10)  //GPG4int sSIOCON,sITVCNT,sSBRDR;#define ZLG7289_ENABLE()	 do{sSIOCON=SIOCON;sITVCNT=ITVCNT;sSBRDR=SBRDR;SIOCON=0x31;ITVCNT=7;SBRDR=200;PDATB&=(~ZLG7289_CS);}while(0)#define ZLG7289_DISABLE()	do{SIOCON=sSIOCON;ITVCNT=sITVCNT;SBRDR=sSBRDR;PDATB|=ZLG7289_CS;}while(0)#define SIOOUT()	do{PDATF&=~0x4;}while(0)#define SIOIN() do{PDATF|=0x4;}while(0)#define Zlg7289_Reset()	 do{write_Zlg7289(ZLG7289_CMD_RST);Delay(20);}while(0)static void Delay(int t){	int i;	for(;t>0;t--)		for(i=0;i<400;i++);}static void write_Zlg7289(char cmd){	I_ISPC |= 0x10;   //中断挂起寄存器清零	SIODAT = cmd;     //准备发送	SIOCON |= 0x9;		 //开始位 [3] 设为1, 开始发送	while( ! (INTPND & 0x10) ); //通过中断挂起寄存器 [4] , 判断停止	I_ISPC |= 0x10;   //\中断挂起寄存器清零}static char read_Zlg7289(){		SIOIN();          //通过PF2设置为输入状态	write_Zlg7289(0);  //发送一无效诉数据	SIOOUT();        //通过PF2设置为输出状态	return SIODAT;    }int keymap[64]={ 7 , 4 , 1 , 4,'N',6,7,8,8,5,				2,0,'/',14,15,16,9,6,3,'.',				'*','-',23,24,'+',26,  27/*enter*/  ,28,29,30,				31,32,33,34,35,36,37,38,39,40,				41,42,43,44,45,46,47,48,49,50,				51,52,53,54,55,56,57,58,59,60,				61,62,63,64				};int zlg7289_getkey(){	int key;	ZLG7289_ENABLE();	write_Zlg7289(ZLG7289_CMD_RDKEY);	key=read_Zlg7289();	ZLG7289_DISABLE();		key=keymap[key];		return key;}static void Zlg7289_showdata(int n){	int i;	for(i=0;i<8 && n!=0 ;i++){		write_Zlg7289(ZLG7289_CMD_DATA1|i); //		write_Zlg7289(n%10);		 Delay(10);		n/=10;	}	for(;i<8;i++){		write_Zlg7289(ZLG7289_CMD_DATA0|i);		write_Zlg7289(0xf);	//don't show any word		 Delay(10);	}}void init_ADdevice(void){	ADCPSR=20;	ADCCON=ADCCON_SLEEP;}static int stop=0;void* comMonitor(void* data){	getchar();	stop=1;	return NULL;}#define ADMID		512int main(void){	//////////////////A,  AB,  B,   BC,   C,  CD, D,    DA	int stepdata[]={0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90};	int i,j,count;	int value=0;	float d;	int key;	pthread_t th_com;	void * retval;	kbd_init();	//set s3c44b0 AD register and start AD	init_ADdevice();	init_exio();	init_MotorPort();	Delay(1);	                                                                      	/* Create the threads */	pthread_create(&th_com, NULL, comMonitor, 0);	while( stop==0 ){		if(!(PDATG&ZLG7289_KEY) )		{			key=zlg7289_getkey();			while( !(PDATG & 0x10) );			printf("%d\n",key);			if(key <=9 && key >= 0)			{				value =value*10 +key;			}			printf("value=%d\n",value);			count = value;			if(key == 27)				value=0;			ZLG7289_ENABLE();				Zlg7289_Reset();			Zlg7289_showdata(value);			ZLG7289_DISABLE();					if(value==0)			{					printf("count=%d\n",count);				printf("waiting...\n");				count=count*4096/360;				for(j=0;j<count;j++)					{						SETEXIOBITMASK(stepdata[j%8], 0xf0);						Delay(20);					}				printf("stop!\n");			}					}	}	/* Wait until producer and consumer finish. */	pthread_join(th_com, &retval);	printf("\n");	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -