این برنامه به صورت spi نرم افزاری تو ccs
#include <18F452.h>
#FUSES HS
#FUSES BORV20
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bi ts=8)
#use spi(DI=PIN_D0, DO=PIN_C1, CLK=PIN_D1, BITS=8,CLOCK_LOW=150,IDLE=1)
//************************************************** *****************
#include <stdio.h>
#include <LCD.h>
#ZERO_RAM
//************************************************** ***********
unsigned int8 data_0,data_1,data_2,data_3,co;
//************************************************** ***********
void re_sp();
void read_sp();
//**********************************************
void main()
{
port_b_pullups(TRUE);
setup_oscillator(OSC_NORMAL);
cls();
delay_ms(200);
while(TRUE){
read_sp();
printf("\f"
;
}
}
//************************************************** *****
void read_sp(){
data_0=spi_xfer(5);
data_1=spi_xfer(5);
data_2=spi_xfer(5);
data_3=spi_xfer(5);
printf("\n1=%u ",data_0);
printf("\n1=%u ",data_1);
printf("\n1=%u ",data_2);
printf("\n1=%u ",data_3);
printf("\n1=%u ",co);
co++;
if(data_3==73) re_sp();
delay_ms(100);
}
//************************************************** *****
void re_sp(){
unsigned int16 word;
printf("\nhadi=%u ",data_0);
printf("\nhadi=%u ",data_1);
printf("\nhadi=%u ",data_2);
printf("\nhadi=%u ",data_3);
word=MAKE16(data_0, data_1);
com(0x80);
printf(WRITE,"AD_READ=%lu ",word);
co=0;
}
#include <18F452.h>
#FUSES HS
#FUSES BORV20
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bi ts=8)
#use spi(DI=PIN_D0, DO=PIN_C1, CLK=PIN_D1, BITS=8,CLOCK_LOW=150,IDLE=1)
//************************************************** *****************
#include <stdio.h>
#include <LCD.h>
#ZERO_RAM
//************************************************** ***********
unsigned int8 data_0,data_1,data_2,data_3,co;
//************************************************** ***********
void re_sp();
void read_sp();
//**********************************************
void main()
{
port_b_pullups(TRUE);
setup_oscillator(OSC_NORMAL);
cls();
delay_ms(200);
while(TRUE){
read_sp();
printf("\f"

}
}
//************************************************** *****
void read_sp(){
data_0=spi_xfer(5);
data_1=spi_xfer(5);
data_2=spi_xfer(5);
data_3=spi_xfer(5);
printf("\n1=%u ",data_0);
printf("\n1=%u ",data_1);
printf("\n1=%u ",data_2);
printf("\n1=%u ",data_3);
printf("\n1=%u ",co);
co++;
if(data_3==73) re_sp();
delay_ms(100);
}
//************************************************** *****
void re_sp(){
unsigned int16 word;
printf("\nhadi=%u ",data_0);
printf("\nhadi=%u ",data_1);
printf("\nhadi=%u ",data_2);
printf("\nhadi=%u ",data_3);
word=MAKE16(data_0, data_1);
com(0x80);
printf(WRITE,"AD_READ=%lu ",word);
co=0;
}
دیدگاه