DEVICE PIC16F887
Define CONFIG1 = 0x23e4 '23e4
Define CONFIG2 = 0x3eff
OSCCON = %01110101 'Oscillator control (datasheet page 66)
'Defines the parameters of the LCD interfacing
Define LCD_BITS = 4
Define LCD_DREG = PORTD
Define LCD_DBIT = 4
Define LCD_RSREG = PORTD
Define LCD_RSBIT = 2
Define LCD_EREG = PORTD
Define LCD_EBIT = 3
Define LCD_RWREG = PORTD
Define LCD_RWBIT = 0
'Defines the parameters of the PSI interfacing
Define SPI_SCK_REG = PORTC
Define SPI_SCK_BIT = 3
Define SPI_SDI_REG = PORTC
Define SPI_SDI_BIT = 4
Define SPI_SDO_REG = PORTC
Define SPI_SDO_BIT = 5
Define SPI_CS_REG = PORTD
Define SPI_CS_BIT = 0
SPIPrepare
AllDigital 'alle ports digital
'declaring variable
Dim ledgreen As Byte
Dim data As Byte
'A gate set to the desired value
'76543210
PORTA = %00000000 'make all ports "PORTA" low
TRISA = %11101111 'RA7,RA6,RA5,RA3,RA2,RA1,RA0 are set for input. RA4, is set for output!
ANSEL = %11000010 '1 = Analog input, RA1,RA6 and RA7 are set for analog input, 0 = digital input, RA0,RA2,RA3,RA4 and RA5 are set digital I/O input.
'B gate set to the desired value
'76543210
PORTB = %00000000 'make all ports "PORTB" low
TRISB = %11111111 'all ports are set for input
WPUB = %11001010 'weak pull-up portB register. 1 = pull-up enabled 0 = pull-up disabled (datasheet page 51)
'C gate set to the desired value
'76543210
PORTC = %00000000 'make all ports "PORTC" low
TRISC = %10111001 'port RC1 & RC2 (CCP1 & CCP2) are set for output
'D gate set to the desired value
'76543210
PORTD = %00000000 'make all ports "PORTD" low
TRISD = %11111111 'are set for input
Lcdinit 0 'no cursor
ledgreen = 1 'turn on the green led!
SPICSOn 'select the RTC bij pulling CS low
SPISend 0x12 'send the write command
SPISend 0x01 'send address for 'seconds'
SPISend 0 'set seconds to zero
SPICSOff 'deselect the RTC bij pulling CS high
main: 'endless loop
SPICSOn 'select the RTC bij pulling CS low
SPISend 0x13 'send the read command
SPISend 0x01 'send address for 'seconds'
SPIReceive data 'recieve data and store it in 'data'
SPICSOff 'deselect the RTC bij pulling CS high
Lcdcmdout LcdClear
Lcdout "Sec "
Lcdcmdout LcdLine1Pos(5)
Lcdout #data
WaitMs 100
Goto main
End 'end program