PDA

View Full Version : Debug SPI using Mikro C/Proteus


leejongfan
26-09-2008, 01:45 AM
Mình có code 1 đoạn SPI (Mater mode) dùng Mikro C cho PIC6f877


void main()
{
ADCON1=0x06; //RA5 Digital I/O
TRISA=0x00; //!RA5=SS: output for Chip Select
TRISC=0x10; //RC5:output SDO
//RC4: Input SDI
//RC3:output SCK
Spi_Init();
PORTA.F5=0; //!SS=0 chip enabled

Spi_Write(0x20); // Power up
Spi_Write(0x00);
Delay_ms(25); //Tpud

Spi_Write(0x20); //Power up
Spi_Write(0x00);
Delay_ms(50); //2 x Tpud

Spi_Write(0xB0); //SETREC from location 0x00
Spi_Write(0x00);

Delay_ms(10000); //delay 10s for recording

Spi_Write(0x30); //STOP
Spi_Write(0x00);

Delay_ms(50); //Tstop;
}


Bây giờ mình ko biết làm sao để check coi code có hoạt động hay ko?
Mình có thử dùng Proteus/SPI debugger dể test,nhưng ko thực sự rành lắm, với lại ko hiểu sao lại xuất hiện Bit -1


https://www.yousendit.com/download/bVlBTkZ1ZDVYSHpIRGc9PQ file .DSN
https://www.yousendit.com/download/bVlBTkZzckk5eFVLSkE9PQ file .PWI
https://www.yousendit.com/download/bVlBTkZzcklFd2NLSkE9PQ file .HEX

Schemantics:

http://i111.photobucket.com/albums/n126/leejongfan/spi.jpg