1 /*********************************************************************
 2     FileName:           PMP.c
 3     Dependencies:       See #includes
 4     Processor:          PIC32MZ
 5     Hardware:           MainBrain MZ
 6     Complier:           XC32 4.40
 7     Author:             Larry Knight 2023
 8 /*********************************************************************
 9  
10     Software License Agreement:
11  
12     Licensed under the Apache License, Version 2.0 (the "License");
13     you may not use this file except in compliance with the License.
14     You may obtain a copy of the License at
15 
16     http://www.apache.org/licenses/LICENSE-2.0
17 
18     Unless required by applicable law or agreed to in writing, software
19     distributed under the License is distributed on an "AS IS" BASIS,
20     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21     See the License for the specific language governing permissions and
22     limitations under the License.
23  
24     Description:
25         System Clock = 200 - 250 MHz
26 
27     File Description:
28 
29     Change History:
30  
31 /***********************************************************************/
32 
33 #include XC.h
34 
35 void PMP_init(void)
36 {
37     //RESET the Module
38     PMCONbits.ON = 0;
39     
40     //PMCON: Parallel Port Control Register
41     PMCONbits.ADRMUX = 0;               //Address and data are separate
42     PMCONbits.PMPTTL = 0;               //Schmitt Trigger input buffer
43     PMCONbits.PTWREN = 1;               //WR enable strobe port
44     PMCONbits.PTRDEN = 1;               //RD enable strobe port
45     PMCONbits.CSF = 0;                  //PMCS1 and PMCS2 not used
46     PMCONbits.CS1P = 0;                 //PMCS1 is active low
47     PMCONbits.WRSP = 0;                 //WR strobe is active low
48     PMCONbits.RDSP = 0;                 //RD strobe is active low
49     PMCONbits.DUALBUF = 1;              //Double Buffer on/off
50     
51     //PMMODE: Parallel Port Mode Register
52     PMMODEbits.IRQM = 0;                //No interrupts
53     PMMODEbits.INCM = 0;                //No auto address inc/dec
54     PMMODEbits.MODE16 = 1;              //16-bit mode
55     PMMODEbits.MODE = 2;                //Master mode 2
56     PMMODEbits.WAITB = 0;               //RD/WR data setup wait states
57     PMMODEbits.WAITM = 1;               //RD/WR data wait states
58     PMMODEbits.WAITE = 0;               //Data hold wait states
59                                                                         
60     //PMADDR: Parallel Port Address Register
61     PMADDRbits.CS2 = 0;                 //PMCS2 is inactive
62     PMADDRbits.CS1 = 0;                 //PMCS1 is inactive
63     
64     //PMAEN: PARALLEL PORT PIN ENABLE REGISTER
65     PMAENbits.PTEN = 0xffff;
66     
67     //RA9 = /CS0 (Display)
68     TRISAbits.TRISA9 = 0;
69     PORTAbits.RA9 = 1;
70     
71     //RA0 = /CS1 (Dual Port RAM)
72     TRISAbits.TRISA0 = 0;
73     PORTAbits.RA0 = 1;    
74     
75     //RA10 = /CS2 (External Flash)
76     TRISAbits.TRISA10 = 0;
77     PORTAbits.RA10 = 1;
78     
79     //Enable the Module
80     PMCONbits.ON = 1;
81 }
82