The purpose of my simulation was to implement Synchronous communication between two PIC's. One as a master and another as a slave. I have read the data sheet in order to understand the configuration before programming both.
So i have programmed both PIC (16f877A) using IDE (MicroC pro) & Simulated the circuit in Proteus-8 professional.
How the circuit should work ? (Kindly check the attached snapshot)
1) The master PIC should acknowledge the IOC(Interrupt on change) at RB5.
2) After moving to IOC ISR, it should transmit the status of PORTA serially to Slave PIC.
3) The Slave PIC should receive the byte & transfer the byte to its PORTB.
Problem : The transmitter (Master PIC) transmits the byte but the "Receiver (Slave PIC) receive-interrupt ISR doesn't execute"
Note : In the Transmit ISR & Receive ISR both contains a line which flip the bits of PORTB. But when i execute the program, it works fine for Master PIC (transmitter) but doesn't work for Slave(Receiver), which means that Transmit ISR execute fine but Receive ISR doesn't execute at all !
Transmitter (Master Code)
Receiver (Slave code)
So i have programmed both PIC (16f877A) using IDE (MicroC pro) & Simulated the circuit in Proteus-8 professional.
How the circuit should work ? (Kindly check the attached snapshot)
1) The master PIC should acknowledge the IOC(Interrupt on change) at RB5.
2) After moving to IOC ISR, it should transmit the status of PORTA serially to Slave PIC.
3) The Slave PIC should receive the byte & transfer the byte to its PORTB.
Problem : The transmitter (Master PIC) transmits the byte but the "Receiver (Slave PIC) receive-interrupt ISR doesn't execute"
Note : In the Transmit ISR & Receive ISR both contains a line which flip the bits of PORTB. But when i execute the program, it works fine for Master PIC (transmitter) but doesn't work for Slave(Receiver), which means that Transmit ISR execute fine but Receive ISR doesn't execute at all !
Transmitter (Master Code)
Code:
/* USRT Transmit module ( Synchronous Transmission ) (Master Mode)
It will transfer data via Tx pin respectively
Baud Rate = 9600
BRGH = 1 (High speep Baud rate generator) -- Used to Minimize the percentage error in baud rate (Visit Data sheet to see it)
Frequency of MCU = 4MHz
For different frequencies, calculate value of SPBRG = [Fosc/4(Desire-Baud.Rate)]-1
Value computed for SPBRG should be convert to Hexa before putting it in SPBRG (as in the below code)
IOC (Interrupt on change) pins [RB4-RB7], when signal status is changed on one of these pins,it will cause interrupt
In ISR module, PORTA [RA0-RA3] will be read in variable "dummy" and transfer synchronously
*/
char dummy = 0x00;
void interrupt(){
if (INTCON.RBIF == 1){ // Change interrupt
PORTB.f0 = !PORTB.f0; // Its just for checking that program execute this section or not (For each PORTB-Change-Interrupt) It works
TXREG = PORTA; // Assign PORTA to Tx reg
dummy=PORTB; // MUST Read PORTB, otherwise flag (RBIF) will not clear
INTCON.RBIF = 0; // Clear flag
}
}
void main()
{
TRISA = 0x0F; TRISB.f0=0; // [RA0-RA3] = Inputs
TRISB.f5 = 1; // RA5 = Input (Used as IOC (interrupt on change))
ADCON1 = 0x06; // PORTA I/O as Digital I/O
SPBRG = 0x67; // decimal = 103, Baud-rate = 9600 , BRGH = 0
TXSTA.SYNC=1; RCSTA.SPEN=1; TXSTA.CSRC=1; // Master clock from BRG, Synchronous mode, Enable Serial ports
TXSTA.TXEN=1; // Transmission Enable
INTCON=0xC8; // {Global interrupts , PORTB Change interrupt} = Enable
while(1);
}
Receiver (Slave code)
Code:
// USRT Recive module ( Synchronous Receiving) (Slave Mode)
char dummy=0x00;
void interrupt(){
if (INTCON.RCIF == 1){ // Byte Received ?
dummy = RCREG; // Read the Byte
PORTB = ~PORTB; // Used for checking whether this ISR is executing after every transmission or NOT ? (IT DOESN'T)
INTCON.RCIF = 0; // Clear Flag
}
}
void main()
{
TRISB = 0x00; // PORTB = Output
TXSTA.SYNC=1; RCSTA.SPEN=1; // Enable Synchronous mode , Enable Serial ports
TXSTA.CSRC=0; // Clock source = Master device
PIE1.RCIE=1; // Recieve interrupt Enable
RCSTA.CREN=1; // Continous receive enable bit
INTCON.GIE=1; INTCON.PEIE=1; // Global and Peripheral interrupts Enable
PORTB = 0x00; // Clear PORTB
while(1); // Do nothing
}
Last edited: