×

PIC单片机SPI通信的设计资料下载

消耗积分:3 | 格式:pdf | 大小:51.83KB | 2021-04-22

彭友旺

分享资料个

#include#define uchar unsigned char#define uint unsigned int#define cs RC2#define dout RC4#define nop() asm(“nop”)__CONFIG(0x3B31);const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};uchar data_temp;void delay(uint x);void init();void didi(uchar num);void disp(uchar num1,uchar num2,uchar num3,uchar num4,uchar num5,uchar num6);void comm(uchar data);uchar read(uchar add);void write(uchar add,uchar wdata);void write_enable();void main(){uchar a1,a2,a3,a4,a5,a6,i;init();//write_enable();//for(i=6;i》0;i--)//{//write_enable();//write(i,i);//}a1=read(1);a2=read(2);a3=read(3);a4=read(4);a5=read(5);a6=read(6);while(1){disp(a1,a2,a3,a4,a5,a6);}}void delay(uint x){uint a,b;for(a=x;a》0;a--)for(b=110;b》0;b--);}void init(){TRISD=0;TRISA=0;TRISC=0x10;//00010000TRISE0=0;SSPSTAT=0x80;SSPCON=0x32;cs=0;}void write_enable(){cs=1;nop();comm(0x02);comm(0x60);cs=0;nop();nop();}void write(uchar add,uchar wdata){cs=1;nop();comm(0x02);comm(add|0x80);comm(wdata);cs=0;nop();nop();cs=1;nop();nop();while(!dout);cs=0;nop();nop();}uchar read(uchar add){uchar rtemp;cs=1;nop();comm(0x03);comm(add);comm(0);cs=0;rtemp=data_temp;return (rtemp);}void comm(uchar data){SSPBUF=data;while(!SSPIF);SSPIF=0;data_temp=SSPBUF;}void didi(uchar num){uchar di_num;for(di_num=num;di_num》0;di_num--){

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !