Hawk44
Newbie level 6
- Joined
- Jan 15, 2014
- Messages
- 12
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 140
Just joined the forum, need some help.
I am using MPLAB 8, C18, and learning to program. I am using a PIC18F45K20 ic.
My code is a little messed up in that I have been trying different things found on the web.
I have gone through the Data sheet and it is confusing when attempting to see what relates to
what with RA0, etc. I am trying to just blink an LED off/on with the ports A. Would like to use all of
them eventually. Sure would like some help, so I can keep on learning, but I am sort of stuck now.
I am also using the demo board for the 18F45K20.
The LED's work fine on portD, But check with voltmeter shows no change on portA, When I move LED to port D, works fine. I conclude that my code is at fault. Perhaps not setting the port A to digital. Changed PBADEN = OFF //disable the analog inputs on RB0 through RB4, but didn't see anything simular for port A.
Here is my code:
Thank you in advance
David :-D
I am using MPLAB 8, C18, and learning to program. I am using a PIC18F45K20 ic.
My code is a little messed up in that I have been trying different things found on the web.
I have gone through the Data sheet and it is confusing when attempting to see what relates to
what with RA0, etc. I am trying to just blink an LED off/on with the ports A. Would like to use all of
them eventually. Sure would like some help, so I can keep on learning, but I am sort of stuck now.
I am also using the demo board for the 18F45K20.
The LED's work fine on portD, But check with voltmeter shows no change on portA, When I move LED to port D, works fine. I conclude that my code is at fault. Perhaps not setting the port A to digital. Changed PBADEN = OFF //disable the analog inputs on RB0 through RB4, but didn't see anything simular for port A.
Here is my code:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 //****************************************************************************** // // ******************************************************************* // PIC18F45K20 PICkit 3 // // // // ******************************************************************* // * * // ******************************************************************* /** C O N F I G U R A T I O N B I T S ******************************/ #pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF // CONFIG1H #pragma config PWRT = OFF, BOREN = OFF, BORV = 30 // CONFIG2L #pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H //#pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC // CONFIG3H orginal #pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC // CONFIG3H #pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // CONFIG5L #pragma config CPB = OFF, CPD = OFF // CONFIG5H #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // CONFIG6L #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // CONFIG7L #pragma config EBTRB = OFF // CONFIG7H // note: PBADEN=OFF DISABLE the analog inputs on RBO THROUGH RB4 /** I N C L U D E S **************************************************/ #include "p18f45k20.h" #include "DELAY.h" /** V A R I A B L E S *************************************************/ #pragma udata // declare statically allocated uinitialized variables unsigned char LED_Display; // 8-bit variable /** D E C L A R A T I O N S *******************************************/ #pragma code // declare executable instructions //PORT D Setting: Set all the pins in port D to Output. //ADCON1=0x0F; // turn all of port A into digital I/O //ADCON1=0b00000000; // turn all of port A into digital I/O void delayzz(void) { int i, j; for(i=0;i<1000;i++) { for(j=0;j<2;j++) { /* Well its Just a Timer */ }}} void main(void) { TRISD = 0b11111111;// Need to set as input then as an output to get output TRISA = 0b11111111; //Need to set as input then as an output to get output delayzz(); //PORT D Setting: Set all the pins in port D to Output. // ADCON1=0x0F; // turn all of port A into digital I/O //ANSEL = 0xE8; //Disables analog input. //ANSELH = 0x00; // e8 TRISD = 0b00000000;// Set all the pins in port D to Output. TRISA = Ob00000000; // Set all the pins in port a to Output. while(1) { delayzz(); Delay100TCYX(78); // 78 x 12.8ms = .9984 s. The timing cycle runs at one-forth of the frequency. LATAbits.LATA0 = 1; // RA-1 Blue on delayzz(); delayzz(); LATAbits.LATA0 = 0; // RA-0 Blue off LATDbits.LATD0 = 1; // RD-0 to High ON 1 delayzz(); delayzz(); LATDbits.LATD1 = 1; // RD-1 to High ON 2 delayzz(); delayzz(); LATDbits.LATD2 = 1; // RD-2 to High ON 3 delayzz(); delayzz(); LATDbits.LATD3 = 1; // RD-3 to High ON 4 delayzz(); delayzz(); delayzz(); delayzz(); LATDbits.LATD0 = 0; // RD-0 to LOW OFF 1 delayzz(); delayzz(); LATDbits.LATD1 = 0; // RD-1 to LOW OFF 2 delayzz(); delayzz(); LATDbits.LATD2 = 0; // RD-2 to LOW OFF 3 delayzz(); delayzz(); LATDbits.LATD3 = 0; // RD-3 to LOW OFF 4 delayzz(); delayzz(); delayzz(); delayzz(); LATDbits.LATD4 = 1; // RD-4 to High ON 5 delayzz(); delayzz(); LATDbits.LATD5 = 1; // RD-5 to High ON 6 delayzz(); delayzz(); LATDbits.LATD6 = 1; // RD-6 to HIGH ON 7 delayzz(); delayzz(); LATDbits.LATD7 = 1; // RD-7 to HIGH ON 6 delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); LATDbits.LATD4 = 0; // RD-4 to LOW OFF 5 delayzz(); delayzz(); LATDbits.LATD5 = 0; // RD-5 to LOW OFF 6 delayzz(); delayzz(); LATDbits.LATD6 = 0; // RD-6 to LOW OFF 7 delayzz(); delayzz(); LATDbits.LATD7 = 0; // RD-7 to LOW OFF 6 delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); delayzz(); //LATDbits.LATD6 = 0; // RD-4 to LOW OFF5 // LATDbits.LATD7 = 0; // RD-5 to LOW OFF6 // delayzz(); } }
Thank you in advance
David :-D
Last edited by a moderator: