01-17-2012 09:02 AM
I am using theESP software on a PIC Microcontroller, and I am not able to program the Count Registers. I can send to each register individually, and read back the data correctly (i.e. write to R-cnt0, read from Rcnt0 looped 0-255, then repeat for Rcnt1, Rcnt2, Rcnt3 and that works). However, whenever I try to program Rcnt0,Rcnt1,Rcnt2,Rcnt3 in that order, I always read back the value sent to Rcnt3 in all 4 registers??? This is being used in the code to control the count of databytes sent/received in 2's complement.
This is my test code below:
while (1)
{
TNT_Out(R_cnt0, 0xAA);
TNT_Out(R_cnt1, 0x55);
Delay10KTCYx(200);//Delay 20K cycles
TNT_Out(R_cnt2, 0xF0);
TNT_Out(R_cnt3, 0xFF);
LATD = 0x00;
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt0);
LATD = Data_Bus; Reads 0xFF here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt1);
LATD = Data_Bus;Reads 0xFF here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt2);
LATD = Data_Bus;Reads 0xFF here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt3);
LATD = Data_Bus;Reads 0xFF here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
}
If I reverse Rcnt0 and Rcnt3:
while (1)
{
TNT_Out(R_cnt0, 0xFF);
TNT_Out(R_cnt1, 0x55);
Delay10KTCYx(200);//Delay 20K cycles
TNT_Out(R_cnt2, 0xF0);
TNT_Out(R_cnt3, 0xAA);
LATD = 0x00;
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt0);
LATD = Data_Bus; Reads 0xAA here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt1);
LATD = Data_Bus;Reads 0xAA here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt2);
LATD = Data_Bus;Reads 0xAA here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
TNT_In(R_cnt3);
LATD = Data_Bus;Reads 0xAA here
Delay10KTCYx(200);//Delay 20K cycles
Delay10KTCYx(200);//Delay 20K cycles
}