tejca
Newbie
I don't know what am I doin wrong.
My code simply don't wanna work.
It is best if I show you all of my code for testing in mikroC.
My code simply don't wanna work.
It is best if I show you all of my code for testing in mikroC.
Code:
//PIC16F1789 and ST95020 SPI eeprom
//RC3 is SCK to Pin 6 on ST95020
//RC4 is SDI to Pin 2 on ST95020
//RC5 is SDO to Pin 5 on ST95020
//RB4 is SS to Pin 1 on ST95020
//WP and HOLD on ST95020 are tied to +5V
#include "__T6963C.h"
sbit T6963C_ctrlcd at RE2_bit; // CD command/data signals pin8 PIC RE2
sbit T6963C_ctrlrd at RA7_bit; // RD read signal pin 6 PIC RA7
sbit T6963C_ctrlwr at RA6_bit; // WR write signal pin 5 PIC RA6
sbit T6963C_ctrlrst at RE1_bit; // RST reset signal pin 10 prej RC4
sbit T6963C_ctrlcd_Direction at TRISE2_bit; // CD command/data signal
sbit T6963C_ctrlrd_Direction at TRISA7_bit; // RD read signal
sbit T6963C_ctrlwr_Direction at TRISA6_bit; // WR write signal
sbit T6963C_ctrlrst_Direction at TRISE1_bit; // RST reset signal
// Signals not used by library, they are set in main function
sbit T6963C_ctrlce at RE0_bit; // CE signal pin 7 PIC RE0
sbit T6963C_ctrlfs at RC0_bit; // FS signal pin 19 PIC RC0
sbit T6963C_ctrlce_Direction at TRISE0_bit; // CE signal direction
sbit T6963C_ctrlfs_Direction at TRISC0_bit; // FS signal direction
sbit CS at RB4_bit;
int stevec, tlong, value, address;
void spi_eeprom_write(unsigned int address,unsigned int value)
{
CS = 0; // enable
SPI1_Write(0x02); // write command for writing data
SPI1_Write(address >> 8);
SPI1_Write(address);
SPI1_Write(value); //write value
CS = 1; // disable
}
unsigned char spi_eeprom_read(unsigned int address) //
{
CS = 0; // enable
SPI1_Write(0x03); // write instruction for read data
SPI1_Write(address >> 8);
SPI1_Write(address);
value = SPI1_Read(0); //read byte
CS = 1; // disable
return value;
}
void main() {
OSCCON = 0b11111000; //16MHz internal oscilator
CM1CON0 = 0x00; // Disable comparators
CM1CON1 = 0x00;
CM2CON0 = 0x00;
CM2CON1 = 0x00;
CM3CON0 = 0x00;
CM3CON1 = 0x00;
DAC1CON0 = 0x00;
DAC1CON1 = 0x00;
PORTA = 0b00111111;
TRISA = 0b00111111;
PORTB = 0b11000000;
TRISB = 0b11000000;
PORTC = 0b11010000;
TRISC.RC0 = 0; // output signal FS for LCD
TRISC.RC1 = 0; // output for PWM2
TRISC.RC2 = 0; // output for PWM1
TRISC.RC3 = 0; // SCL as output
TRISC.RC4 = 1; // SDI as input
TRISC.RC5 = 0; // SDO as output
TRISC.RC6 = 1; // input for key
TRISC.RC7 = 1; // input for key
TRISD = 0x00; // Port D as output
PORTE = 0b00001000;
TRISE = 0b00001000; // Port E as input
ANSELA = 0b00000000; // no analog inputs
ANSELB = 0b00000000;
ANSELC = 0b00000000;
ANSELD = 0b00000000;
ANSELE = 0x00;
APFCON1 = 0b00000000;
APFCON2 = 0b00000100; // SS on pin RB4
T6963C_ctrlce_Direction = 0;
T6963C_ctrlce = 0; // Enable T6963C
T6963C_ctrlfs_Direction = 0; // set font
T6963C_ctrlfs = 0;
delay_ms(1);
T6963C_init(240, 64, 8); // Initialize T6963C
T6963C_text(1);
T6963C_cursor(0); // cursor = off
T6963C_panelFill(0); //Clear LCD screen
value = 28; //some randome value for testing
address = 0;
SPI1_Init();
spi_eeprom_write(0x58, value); //some random address for testing
delay_ms(10);
while (1) {
stevec = spi_eeprom_read(0x58); //save to stevec
tlong = stevec / 10;
T6963C_write_char(48+tlong, 10, 0, T6963C_ROM_MODE_XOR);
tlong = stevec % 10;
T6963C_write_char(48+tlong, 11, 0, T6963C_ROM_MODE_XOR);
}
}