Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * CDP1802b6 21/3/203:47 Issues woth serial.available slowing down reads of 1802 data. Trying new Norwegian code.
- * 3:57, works witrh dummy commands.
- * . Start of array use for instructions
- Had big problems with first TPB cycle. Seemed to get old address outp[ut on address bus low when
- ..it should have been zero after reset. Round about the 4th clock after reset, adress goes to old value before reset.
- ..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
- ..activated on first cycle so maybe just nop in zero position and move on?
- ..Next, connect up BUS pins to C port on mega. Initially just output nops, then when needed by instruction fetch, then chnage
- .. to little program that plays with Q and does loop involving nops too. This program has too many diagnostic entries so will tidy up
- .. before trying next version.
- Tidied up and working with resistors connecting data bus to $C4 pattern = nop.
- Now going to send constant $C4 via PORTC of Mega2650 to breadboard containing 1802. PORTC-->BUS 1802 all the time. Should be the
- ..same as resistor to rail $C4 above. Worked 10:07
- Now try sending $c4 only when clk goes low and TPB is high.Worked 10:19.
- 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
- Now going to select nop from an array of nops. Worked with just one element of arry of instructions called vRAM[]. Do several next.
- Key change was [ byte vRAM[5] = {0xc4, 0xc4, 0xc4, 0xc4, 0x00}; ] Next add instructions to turn on and off Q flag.
- Now going to put in little sequence of instructions. Key change is: [ byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00};
- //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}; ]
- Now gpoing to turn Q on and off but with branch back to start. Worked OK.
- 11:27am 20/3/20. Adding in dump of vertual ram array as well as issuing commands from serial terminal.
- ..Practiced some of the routines in dumper3.
- Going well, apart from serial read issues, but basic 1820 stuff going well. Try new serial read instruction code.
- */
- //1802 talks to Arduino Mega
- #define clockPin 13
- #define clearPin 12
- #define TPBpin A1
- #define readPin A15 //the *MRD of 1802
- #define SC0pin A12 //When SC0=LOW it's a fetc h, when HI it's executing
- #define DELAY 50
- int val = 0; int bufBytes, TPBCtr, clkCtr = 0;
- int adrByte=0;
- //byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00}; //ie nop,seq,nop,req,idl
- //byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; //ie nop,seq,nop,req,idl
- byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0x7a, 0x30, 0x00,0x00}; //ie seq,seq,req,seq,br start, idl
- void setup() {
- pinMode(clockPin, OUTPUT);
- pinMode(clearPin, OUTPUT);
- pinMode(TPBpin,INPUT);
- pinMode(readPin,INPUT);
- pinMode(SC0pin,INPUT);
- DDRA=0x00; //DDRA reads Adress port of 1802. All inputs
- DDRC=0x00; //PORTC connects to 1802 data BUS.
- Serial.begin(9600); // open the serial port at 9600 bps:
- serialFlush();
- Serial.flush();
- Serial.println("Arduino talks to 1802. Pb 2020");
- delay(500);
- doReset();
- // vRAM[1] = 0xc4;
- dumpVert();
- }
- void loop() {
- // SRB();
- norwayCommand();
- digitalWrite(clockPin, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(DELAY); // wait for a second
- digitalWrite(clockPin, LOW); // turn the LED off by making the voltage LOW
- DDRC=0x00; //DDRC usually input except when sending instruction
- clkCtr++; //how many clocks after reset?
- if (digitalRead(TPBpin) ==HIGH) {
- doTPBWork();
- }
- delay(DELAY); // wait for a second
- }
- void doTPBWork(void) {
- TPBCtr++;
- //DDRC=0xff; //make mega data port output
- //PORTC = 0xc4; //send nop
- Serial.print("TPB with clock low. Num=");
- Serial.print(TPBCtr);
- Serial.print(" Clocks=");
- Serial.print(clkCtr);
- Serial.print(" AdrL=");
- adrByte = PINA;
- Serial.print(PINA,HEX);
- if (digitalRead(readPin)==LOW) {
- DDRC = 0xff; //just for this version. Send nop when clk goes 1 to 0, TPB =1, MRD=0
- PORTC = vRAM[adrByte] ; //0xc4; //constant noop
- Serial.print(" %R ");
- Serial.print(vRAM[adrByte],HEX);
- }
- if(digitalRead(SC0pin)==LOW) {
- Serial.print(" F "); //fetching instruction
- }
- else {
- Serial.print(" E "); //executing instruction
- }
- Serial.println(" ]");
- }
- void doReset(void){
- digitalWrite(clearPin,LOW); //bring CLEAR low for about 10 clocks to reset 1802
- for(int i =0;i<=10;i++) {
- digitalWrite(clockPin, HIGH);
- delay(DELAY); // wait
- digitalWrite(clockPin, LOW);
- delay(DELAY);
- }// 10 clocks low should reset 1802
- digitalWrite(clearPin,HIGH); //bring back to RUN mode
- }
- void serialFlush(){
- while(Serial.available() > 0) { //while there are characters in the serial buffer, because Serial.available is >0
- char t = Serial.read(); // get one character
- }
- }
- void showLenOfTxBuffer(void) {
- bufBytes=Serial.availableForWrite();
- Serial.print(bufBytes);
- Serial.println("~");
- }
- void dumpVert(void) {
- char data[100];
- Serial.print("Col: ");
- for(int i=0;i<16;i++) {
- sprintf(data, "%02x ",i);
- Serial.print(data);
- if(i==7) Serial.print(" ");
- }
- for (int i=0;i<256;i++){
- if (i%16 == 0){
- Serial.println ("");
- sprintf(data, "%02x ",i);
- Serial.print(data);
- }
- if(i%8==0) { Serial.print("|"); }
- sprintf(data, " %02x ",vRAM[i]);
- Serial.print(data);
- }
- Serial.println(" ");
- }
- void doDump(void) {
- Serial.println("Got a dump");
- dumpVert();
- }
- void doGetProgram(void){
- Serial.println("Doing getProgram.");
- }
- void SRB(){
- byte k;
- byte buff[10];
- k = Serial.readBytes(buff, 3);
- if (k>0) {
- //Serial.println(k);
- for (int i = 0;i<k;i++) {
- // Serial.println(buff[i],HEX);
- }
- if ((buff[0] ==0x64) && (buff[1] == 0x75 )) doDump(); //"du" = dump array
- if ((buff[0] ==0x67) && (buff[1] == 0x70 )) doGetProgram(); //"gp = get program, via serial
- //Serial.println("Got a dump");
- }
- }
- void norwayCommand(void){ //trying better instruction method from serial https://www.norwegiancreations.com/2017/12/arduino-tutorial-serial-inputs/
- String command;
- if(Serial.available()){
- command = Serial.readStringUntil('\n');
- if(command.equals("init")){
- Serial.print("i"); //nitialize();
- }
- else if(command.equals("send")){
- Serial.print("s");
- }
- else if(command.equals("data")){
- Serial.print("d");
- }
- else if(command.equals("reboot")){
- Serial.print("r");
- }
- else if(command.equals("du")){
- Serial.print("Dumper");
- dumpVert();
- }
- else{
- Serial.println("Invalid command");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement