hallo ik ben net begonnen met het pic programmeren en heb een redelijk goed boek gevonden, dit boek werkt met de 4525...ik kon online echter enkel de 4620 vinden. Ik had deze besteld omdat ze dezelfde 'familie' vormen. Echter de voorbeeldjes uit het boek werken niet en programmaatjes voor de 4620 wel zie onder. Kan iemand mij op weg helpen?
4525:deze werkt dus niet
4620: deze werkt wel
4525:deze werkt dus niet
C:
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
| /* * File: list3-2.c * Author: kees * * Created on 15 February 2023, 14:13 */ #include <xc.h> int main(void) //This defines the start of the // main loop { TRISA = 0x0b00000000; //Make all bits on PORTA inputs TRISB = 0x0b11111111; //Make all bits on PORTB outputs ADCON0 = 0x00; //This turns the ADC off ADCON1 = 0x0F; //This sets all the bits on PORTA //as digital OSCCON = 0b01110100; //set the internal oscillator to // 8Mhz stable T0CON = 0X87; //set TMR0 to on and 16bit with max // divide rate Freq = 7812.5Hz //one tick takes 128us. while (1) //The forever loop { //This defines the start of the // forever loop while (PORTAbits.RA0 == 0) ; //Do nothing while // the logic at b0 //of PORTA is at //logic '0' TMR0 =0; //make sure TMR0 // starts counting //from while (TMR0 < 7812); //Do nothing until // TMR0 has counted //up to 7812. This //equates to a one //second delay PORTBbits.RB0 = 1; //Turn on what is // connected to b0 //of PORTB while (PORTAbits.RA1 == 0) ; //Do nothing while //the logic at b1 of //PORTA is at logic //'0'. PORTBbits.RB0 = 0; //Turn on what is //connected to b0 // of PORTB } //This defines the end of the forever loop } //This defines the end of the main loop ------------------------------------------------------ |
4620: deze werkt wel
C:
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
| /* * File: test7.c * Author: kees * * Created on 15 February 2023, 14:57 */ // Flash LED at a different rate depending on whether RD4 is high or low #include <xc.h> #pragma config OSC=INTIO67,MCLRE=OFF,WDT=OFF,LVP=OFF,BOREN=OFF int main(void) { // Make RD0 a digital output - all other PORT D are inputs TRISD = 0b11111110; while(1) { if(PORTDbits.RD4 == 1) { LATDbits.LATD0 = 1; // Set pin RD0 high _delay(60000); LATDbits.LATD0 = 0; // Set pin RD0 low _delay(60000); } else { LATDbits.LATD0 = 1; // Set pin RD0 high _delay(125000); LATDbits.LATD0 = 0; // Set pin RD0 low _delay(125000); } } } |
[Voor 0% gewijzigd door SA007 op 16-02-2023 11:20. Reden: code tag erbij voor leesbaarheid]