C语言程序例程5
C语言程序例程//该程序用于在8个LED上依次显示1~8#include"p18f458.h"staticvolatileinttable[20]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0XD8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x7f,0xbf,0x89,0xff};volatileunsignedchardata;/*初始化子程序*/voidinitial(){TRISA=0x00;/*A口设置为输出*/TRISC=0x00;/*SDO引脚为输出,SCK引脚为输出*/INTCON=0x00;/*关闭所有中断*/SSPCON1=0x30;/*SSPEN=1;CKP=1,FOSC/4*/SSPSTAT=0xC0;/*时钟下降沿发送数据*/PIR1=0;/*清除SSPIF标志*/}/*显示子程序*/voidSPILED(chardata){PORTAbits.RA5=0;/*LACK送低电平,为锁存做准备*/SSPBUF=data;/*启动发送*/do{;}while(PIR1bits.SSPIF==0);/*等待发送完毕*/PIR1bits.SSPIF=0;
用户评论