完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这是代码,哪位大佬看一哈
#include #include "SPI.h" #include "intrins.h" unsigned char RX_dat[20]; unsigned char RXflage; unsigned long Rx_Freq; unsigned long HMC704_03; double temp; unsigned long temp_ulong; unsigned long cfgdat; void Set8562(unsigned long datin) { unsigned long dat; unsigned char i = 0; unsigned char ii = 0; DAC8562_CS = 0; dat = datin; dat = dat << 8; for(i = 0;i < 24;i++) { DAC8562_CLK = 1; DAC8562_DAT = dat & 0x80000000; dat = dat << 1; DAC8562_CLK = 0; } DAC8562_DAT = 0; DAC8562_CLK= 0; dat = dat << 1; DAC8562_CS = 1; } void init_dac8562() { cfgdat = 0x380001; Set8562(cfgdat); cfgdat = 0x184000; // cfgdat = 0x100000; Set8562(cfgdat); cfgdat = 0x194000; // cfgdat = 0x120000; Set8562(cfgdat); } void cfg_dac8562_1(unsigned long datin) { cfgdat = 0x180000+datin; Set8562(cfgdat); } 他的主函数 #include #include "string.h" #include #include "SPI.h" #include unsigned char index = 1; unsigned char buf[2]; unsigned char flag = 0; unsigned char UART_RX_idx = 0; void re(unsigned char a); void delay(unsigned long delaytime) { for(;delaytime>0;delaytime--) _nop_(); } void delay10000(unsigned long delaytime) { unsigned long i; for(;delaytime>0;delaytime--) for(i = 0;i <10000;i++) _nop_(); } void UART_Init() { EA = 0; SCON0 = 0x50; TCON = 0x40; TMOD = 0x20; TH1 = 0x96; CKCON = 0x00; TR1 = 1; ET0= 1; ES0 =1; TI0 = 0; RI0 = 0; EA = 1; UART_RX_idx = 0; RXflage = 0; } void Send_data(unsigned char dat) { SBUF0 = dat; TI0 = 1; delay(10); while(!TI0); } void uart() interrupt 4 { unsigned char aa; if(RI0) { EA = 1; RI0 = 0; aa = SBUF0; re(aa); } } void re(unsigned char a) { switch(index) { case 1://正在等待接受0xaa if(a == 0xaa) { //继续接受0x55; index++; } else { index =0; } break; case 2: { if(a == 0x55) { //继续接受0x55; index++; } else { index =0; } } break; case 3: { buf[0] = a; index++; } break; case 4: { buf[1] = a; index++; } break; case 5: if(a == ' ) { index++; } else { index =0; } break; case 6: if(a == '&') { flag = 1; } else { index =0; } break; } } void main (void) { PCA0MD &= ~0x40; OSCICN |= 0x03; XBR0 = 0x01; XBR1 = 0x40; P0MDIN |= 0x00; P1MDIN |= 0x00; P0MDOUT|= 0xff; P1MDOUT|= 0xff; UART_Init(); delay10000(20); init_dac8562(); cfg_dac8562_1(); { while(1) { if(flag == 1) { cfg_dac8562_1(buf[0]*256+buf[1]); flag = 0; } } } } |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1168 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1105 浏览 2 评论
2203 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1297 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1718 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 19:38 , Processed in 0.621283 second(s), Total 70, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号