整个程序都是自己写的,是以前做的几个程序拼成的,应该看的出来的,一个是sendf,一个是主程序,两个部分分开运行都是ok的,但是和在一起,编译通过之后通过jtag发到lm3s9b96c5,貌似写不进去,不知道为什么,想了很久,请大师指教,下面是程序,关键请关注倒数几行的一个注释
#include "inc/hw_ssi.h" #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/ssi.h" #include "driverlib/gpio.h" #include "driverlib/sysctl.h" #define BUFFER_SIZE 28 #include <math.h> void delay(long int i) {for(;i;i--);} void cpuinit(void) {
SysCtlClockSet(SYSCTL_SYSDIV_6 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); } void sendf(float b) { char a[6][4]; int f,n1,n2,n3,n4,n5,n6; int i; GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_0) ; GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_1) ; GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_2) ; GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_3) ; GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE,GPIO_PIN_2) ; f=(int)(b*1000);f=f/25;n1=f%16;f=f/16; n2=f%16;f=f/16;n3=f%16;f=f/16;
n4=f% 16;f=f/16;n5=f%16;n6=f/16; a[0][0]=n6%2;n6=n6/2;a[0][1]=n6%2;n6=n6/2;a[0][2]=n6%2;a[0][3]=n6/2; a[1][0]=n5%2;n5=n5/2;a[1][1]=n5%2;n5=n5/2;a[1][2]=n5%2;a[1][3]=n5/2; a[2][0]=n4%2;n4=n4/2;a[2][1]=n4%2;n4=n4/2;a[2][2]=n4%2;a[2][3]=n4/2; a[3][0]=n3%2;n3=n3/2;a[3][1]=n3%2;n3=n3/2;a[3][2]=n3%2;a[3][3]=n3/2; a[4][0]=n2%2;n2=n2/2;a[4][1]=n2%2;n2=n2/2;a[4][2]=n2%2;a[4][3]=n2/2; a[5][0]=n1%2;n1=n1/2;a[5][1]=n1%2;n1=n1/2;a[5][2]=n1%2;a[5][3]=n1/2; GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_2,0x00); for(i=0;i<6;i++) {
GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_0,a[0]); GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_1,a[1]<<1); GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_2,a[2]<<2); GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_3,a[3]<<3); GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_2,0x04); delay(1000); GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_2,0x00);delay(1000);} delay(10000) ;
} int main() { float fref=55; //被测频率 int m=0,j,a,i,c=0,d; long int b=0; int temp[16],in[5]; char aa[5][BUFFER_SIZE]; cpuinit();
sendf(fref); delay(1000000); for(m=0;m<16;m++) { temp[m]=0; } GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_2) ; GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_3) ; GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_4) ; GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_5) ; GPIOPinTypeGPIOInput(GPIO_PORTA_BASE,GPIO_PIN_6) ; GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE,GPIO_PIN_7) ; GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE,GPIO_PIN_7) ; d=0x2800;c=0; // d=0x2c80; while(abs(c-0x1daa)>0x60) { a=d; for(m=0;m<16;m++) { temp[m]=a%2; a=a/2 ; } GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_7,0x00); for(m=15;m>-1;m--) { GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_5,(temp[m]<<5)); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,0x04); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,0x00); } delay(50); GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_7,0x80); delay(500); for(j=0;j<5;j++) { GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0x08); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,0x80); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,0x00); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_7,0x80); while(1) { if(GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_6)==0) { break; } } GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0x00); ;;;;;; /* for(i = 0;i < BUFFER_SIZE; i++) ///* */之间为疑似错误区域,去掉程序可以导入cpu,不去掉则不能 { GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,0x04); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_2,0x00); aa[j]=(char)(GPIOPinRead(GPIO_PORTA_BASE,GPIO_PIN_4) ); //第一组数据要抛弃,实际取的为28位中的后14位 } GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0x08); delay(50); for(i=0,b=0;i<14;i++) { b=b*2+aa[j] ; } ;;;;;; in[j]=b/0x10; */ } for(i=1,c=0;i<5;i++) { c+=in; } c=c/4; if((c-0x2000)>0x60) { d=d+0x20; } if((0x2000-c)>0x60) { d=d-0x20; } delay(2500) ; } }
|