Advertisement
prjbrook

1802 talks to mega A

Mar 22nd, 2020
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. /**
  2. * CDP1802b6 21/3/203:47 Issues woth serial.available slowing down reads of 1802 data. Trying new Norwegian code.
  3. * 3:57, works witrh dummy commands.
  4. * . Start of array use for instructions
  5. Had big problems with first TPB cycle. Seemed to get old address outp[ut on address bus low when
  6. ..it should have been zero after reset. Round about the 4th clock after reset, adress goes to old value before reset.
  7. ..Settles down into next cycles with consistent addresses 1,2,3,4. But adr=0 remains a problem. The read line doesn't seem to be
  8. ..activated on first cycle so maybe just nop in zero position and move on?
  9. ..Next, connect up BUS pins to C port on mega. Initially just output nops, then when needed by instruction fetch, then chnage
  10. .. to little program that plays with Q and does loop involving nops too. This program has too many diagnostic entries so will tidy up
  11. .. before trying next version.
  12. Tidied up and working with resistors connecting data bus to $C4 pattern = nop.
  13. Now going to send constant $C4 via PORTC of Mega2650 to breadboard containing 1802. PORTC-->BUS 1802 all the time. Should be the
  14. ..same as resistor to rail $C4 above. Worked 10:07
  15. Now try sending $c4 only when clk goes low and TPB is high.Worked 10:19.
  16. Now try sending nop from mega to 1802 bus only when 1) clock goes low,2) TPB is high and 3) read is low. Worked 10:24
  17. Now going to select nop from an array of nops. Worked with just one element of arry of instructions called vRAM[]. Do several next.
  18. Key change was [ byte vRAM[5] = {0xc4, 0xc4, 0xc4, 0xc4, 0x00}; ] Next add instructions to turn on and off Q flag.
  19. Now going to put in little sequence of instructions. Key change is: [ byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00};
  20. //ie nop,seq,nop,req,idl ] Worked and got Q flag going on and off with this; [byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; ]
  21. Now gpoing to turn Q on and off but with branch back to start. Worked OK.
  22. 11:27am 20/3/20. Adding in dump of vertual ram array as well as issuing commands from serial terminal.
  23. ..Practiced some of the routines in dumper3.
  24. Going well, apart from serial read issues, but basic 1820 stuff going well. Try new serial read instruction code.
  25. */
  26.  
  27. //1802 talks to Arduino Mega
  28. #define clockPin 13
  29. #define clearPin 12
  30. #define TPBpin A1
  31. #define readPin A15 //the *MRD of 1802
  32. #define SC0pin A12 //When SC0=LOW it's a fetc h, when HI it's executing
  33. #define DELAY 50
  34.  
  35. int val = 0; int bufBytes, TPBCtr, clkCtr = 0;
  36. int adrByte=0;
  37. //byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00}; //ie nop,seq,nop,req,idl
  38. //byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; //ie nop,seq,nop,req,idl
  39. byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0x7a, 0x30, 0x00,0x00}; //ie seq,seq,req,seq,br start, idl
  40. void setup() {
  41.  
  42. pinMode(clockPin, OUTPUT);
  43. pinMode(clearPin, OUTPUT);
  44. pinMode(TPBpin,INPUT);
  45. pinMode(readPin,INPUT);
  46. pinMode(SC0pin,INPUT);
  47. DDRA=0x00; //DDRA reads Adress port of 1802. All inputs
  48. DDRC=0x00; //PORTC connects to 1802 data BUS.
  49. Serial.begin(9600); // open the serial port at 9600 bps:
  50. serialFlush();
  51. Serial.flush();
  52. Serial.println("Arduino talks to 1802. Pb 2020");
  53. delay(500);
  54. doReset();
  55. // vRAM[1] = 0xc4;
  56. dumpVert();
  57. }
  58.  
  59.  
  60. void loop() {
  61. // SRB();
  62. norwayCommand();
  63. digitalWrite(clockPin, HIGH); // turn the LED on (HIGH is the voltage level)
  64. delay(DELAY); // wait for a second
  65. digitalWrite(clockPin, LOW); // turn the LED off by making the voltage LOW
  66. DDRC=0x00; //DDRC usually input except when sending instruction
  67. clkCtr++; //how many clocks after reset?
  68.  
  69. if (digitalRead(TPBpin) ==HIGH) {
  70. doTPBWork();
  71. }
  72. delay(DELAY); // wait for a second
  73. }
  74. void doTPBWork(void) {
  75. TPBCtr++;
  76. //DDRC=0xff; //make mega data port output
  77. //PORTC = 0xc4; //send nop
  78. Serial.print("TPB with clock low. Num=");
  79. Serial.print(TPBCtr);
  80. Serial.print(" Clocks=");
  81. Serial.print(clkCtr);
  82. Serial.print(" AdrL=");
  83. adrByte = PINA;
  84. Serial.print(PINA,HEX);
  85. if (digitalRead(readPin)==LOW) {
  86. DDRC = 0xff; //just for this version. Send nop when clk goes 1 to 0, TPB =1, MRD=0
  87. PORTC = vRAM[adrByte] ; //0xc4; //constant noop
  88.  
  89. Serial.print(" %R ");
  90. Serial.print(vRAM[adrByte],HEX);
  91. }
  92. if(digitalRead(SC0pin)==LOW) {
  93. Serial.print(" F "); //fetching instruction
  94. }
  95. else {
  96. Serial.print(" E "); //executing instruction
  97. }
  98. Serial.println(" ]");
  99. }
  100. void doReset(void){
  101. digitalWrite(clearPin,LOW); //bring CLEAR low for about 10 clocks to reset 1802
  102. for(int i =0;i<=10;i++) {
  103. digitalWrite(clockPin, HIGH);
  104. delay(DELAY); // wait
  105. digitalWrite(clockPin, LOW);
  106. delay(DELAY);
  107. }// 10 clocks low should reset 1802
  108. digitalWrite(clearPin,HIGH); //bring back to RUN mode
  109.  
  110. }
  111. void serialFlush(){
  112. while(Serial.available() > 0) { //while there are characters in the serial buffer, because Serial.available is >0
  113. char t = Serial.read(); // get one character
  114. }
  115. }
  116. void showLenOfTxBuffer(void) {
  117. bufBytes=Serial.availableForWrite();
  118. Serial.print(bufBytes);
  119. Serial.println("~");
  120. }
  121.  
  122. void dumpVert(void) {
  123. char data[100];
  124. Serial.print("Col: ");
  125. for(int i=0;i<16;i++) {
  126. sprintf(data, "%02x ",i);
  127. Serial.print(data);
  128. if(i==7) Serial.print(" ");
  129. }
  130. for (int i=0;i<256;i++){
  131. if (i%16 == 0){
  132. Serial.println ("");
  133. sprintf(data, "%02x ",i);
  134. Serial.print(data);
  135. }
  136. if(i%8==0) { Serial.print("|"); }
  137. sprintf(data, " %02x ",vRAM[i]);
  138. Serial.print(data);
  139. }
  140. Serial.println(" ");
  141. }
  142. void doDump(void) {
  143. Serial.println("Got a dump");
  144. dumpVert();
  145. }
  146. void doGetProgram(void){
  147. Serial.println("Doing getProgram.");
  148. }
  149. void SRB(){
  150. byte k;
  151. byte buff[10];
  152. k = Serial.readBytes(buff, 3);
  153. if (k>0) {
  154. //Serial.println(k);
  155.  
  156. for (int i = 0;i<k;i++) {
  157. // Serial.println(buff[i],HEX);
  158. }
  159. if ((buff[0] ==0x64) && (buff[1] == 0x75 )) doDump(); //"du" = dump array
  160. if ((buff[0] ==0x67) && (buff[1] == 0x70 )) doGetProgram(); //"gp = get program, via serial
  161. //Serial.println("Got a dump");
  162. }
  163. }
  164. void norwayCommand(void){ //trying better instruction method from serial https://www.norwegiancreations.com/2017/12/arduino-tutorial-serial-inputs/
  165. String command;
  166. if(Serial.available()){
  167. command = Serial.readStringUntil('\n');
  168.  
  169. if(command.equals("init")){
  170. Serial.print("i"); //nitialize();
  171. }
  172. else if(command.equals("send")){
  173. Serial.print("s");
  174. }
  175. else if(command.equals("data")){
  176. Serial.print("d");
  177. }
  178. else if(command.equals("reboot")){
  179. Serial.print("r");
  180. }
  181. else if(command.equals("du")){
  182. Serial.print("Dumper");
  183. dumpVert();
  184. }
  185. else{
  186. Serial.println("Invalid command");
  187. }
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement