Toon posts:

verschil pic pic18f4620 en pic 18f4525

Pagina: 1
Acties:

  • vincent87
  • Registratie: Februari 2023
  • Laatst online: 29-03 13:36
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
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]


  • SA007
  • Registratie: Oktober 2002
  • Laatst online: 21:36

SA007

Moderator Tweaking
Ik ben niet heel erg thuis in de PIC familie, maar wat is jouw idee bij 'werkt niet'?

Krijg je compile errors, wat doet de programmer, etc.

Verder zie ik wel dat de eerste code vrij uitgebreid timers gebruikt, dit zijn delen die vaak tussen series en modellen van chips anders zijn (meer of minder timers, andere bits, features etc)

Klok is stuk :(


  • vincent87
  • Registratie: Februari 2023
  • Laatst online: 29-03 13:36
hoi, bij compilen geeft hij geen error ik kan hem oploaden naar de controller, echter ik meet niets op de uitgangen bij het andere programmaatje wel....ik zie niet waar de fout zit de 4525 is nagenoeg identiek aan de 4620

  • DaWaN
  • Registratie: Oktober 2002
  • Laatst online: 12:57

DaWaN

'r you wicked ??

Je zult denk ik de datasheets even naast elkaar moeten leggen om te kijken of de registers die in de voorbeelden gebruikt worden identieke functies hebben bij de 4525 en 4620.
Dan voornamelijk de OSCCON en T0CON, de timer en de oscillator.
Ook zit er in het tweede voorbeeld een pragma met de config, het ontbreken daarvan in het eerste voorbeeld kan uiteraard ook nog roet in het eten gooien.
En zoals @Larry4 ook al meldt; het eerste voorbeeld doet niets zolang je pinnen RA0 en RA1 niet aanstuurt.
Fouten tijdens het compileren hoort ook niet; zonder de exacte foutmelding kunnen wij daar ook weinig over zeggen.

If you do not change direction, you may end up where you are heading


  • vincent87
  • Registratie: Februari 2023
  • Laatst online: 29-03 13:36
ik heb de pragma van het tweede programma gebruikt , de fout lijkt in het boren statement te zitten...ik kan weer verder, bedankt!

  • vincent87
  • Registratie: Februari 2023
  • Laatst online: 29-03 13:36
/* File: 24hr clok.c
* Author: kees
*
* Created on 21 February 2023, 15:22*/


/*A program to control a 24Hr clok
Displayed on 4 seven-segment display
Written for the PIC18f by Mr H. H. Ward
dated 15/01/2019 */


// PIC18F4620 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1H
#pragma config OSC = INTIO67 // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
#pragma config BORV = 3 // Brown Out Reset Voltage bits (Minimum setting)

// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = PORTC // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = OFF // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-003FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (004000-007FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (008000-00BFFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (00C000-00FFFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (00C000-00FFFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include "xc.h"


//Some definitions
#define zero 0b01000000
#define one 0b01111001
#define two 0b00100100
#define three 0b00110000
#define four 0b00011001
#define five 0b00010010
#define six 0b00000011
#define seven 0b01111000
#define eight 0b00000000
#define nine 0b00011000
#define incButton PORTEbits.RE0
#define decButton PORTEbits.RE1
#define setButton PORTEbits.RE2
//some variables
unsigned char n, m;
unsigned char minUnits = 0, minTens = 0, hourUnits = 0, hourTens = 0;
//some subroutines
void debounce ()
{
TMR0 = 0;
while (TMR0 < 101);
}
//some arrays
unsigned char displaynumber [10] =
{
zero,
one,
two,
three,
four,
five,
six,
seven,
eight,
nine,
};
void main ()
{
initialise ();
TRISA = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0;
TRISE = 0xFF;

//set minutes
minunitsset:
PORTA = displaynumber [minUnits];
if (incButton)debounce ();
if (incButton)
{
minUnits ++;
while (incButton);
PORTA = displaynumber [minUnits];
}
if (decButton )debounce ();
if (decButton)
{
if (minUnits > 0) minUnits --;
else minUnits = 0;
while (decButton);
PORTA = displaynumber [minUnits];
}
if (setButton) debounce ();
if (setButton) goto mintensset;
goto minunitsset;
//**************************************************
mintensset:while (setButton);
PORTB = displaynumber [minTens];
if (incButton)debounce ();
if (incButton)
{
if (minTens < 6)
minTens ++;
else minTens = 6;
while (incButton);
PORTB = displaynumber [minTens];
}
if (decButton)debounce ();
if (decButton)
{
if (minTens > 0)
minTens --;
else minTens = 0;
while (decButton);
PORTB = displaynumber [minTens];
}
if (setButton) debounce ();
if (setButton) goto hoursunitsset;
goto mintensset;
//sethours
hoursunitsset: while (setButton);
PORTC = displaynumber [hourUnits];
if (incButton)debounce ();
if (incButton)
{
hourUnits ++;
while (incButton);
PORTC = displaynumber [hourUnits];
}
if (decButton)debounce ();
if (decButton)
{
if (hourUnits > 0)
hourUnits --;
else hourUnits = 0;
while (decButton);
PORTC = displaynumber [hourUnits];
}
if (setButton) debounce ();
if (setButton) goto hourstensset;
goto hoursunitsset;
//**************************************************
hourstensset: while (setButton);
PORTD = displaynumber [hourTens];
if (incButton)debounce ();
if (incButton)
{
if (hourTens < 2)
hourTens ++;
else hourTens = 2;
while (incButton);
PORTD = displaynumber [hourTens];
}
if (decButton)debounce ();
if (decButton)
{
if (hourTens > 0)
hourTens --;
else hourTens = 0;
while (decButton);
PORTD = displaynumber [hourTens];
}
if (setButton) debounce ();
if (setButton) goto clock;
goto hourstensset;
//*************************************************
clock: while (1)
{
for (m = 0; m <60; m++)
{
for (n = 0; n <29; n++)
{
TMR0 = 0;
while (TMR0 < 255);
}
}
minUnits ++;
if (minUnits == 10)
{
minUnits = 0;
minTens ++;
if (minTens == 6)
{
minTens = 0;
hourUnits ++;
if (hourTens < 2)
{
if (hourUnits == 10)
{
hourUnits = 0;
hourTens ++;
}
}
else if (hourTens == 2)
{
if (hourUnits == 4)
{
hourUnits = 0;
hourTens =0;
}
}
}
}
PORTA = displaynumber [minUnits];
PORTB = displaynumber [minTens];
PORTC = displaynumber [hourUnits];
PORTD = displaynumber [hourTens];
}
}

als ik deze poortcommandos geef , loopt hij vat op de volgende commando's
initialise ();
TRISA = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0;
TRISE = 0xFF;

24tst.c:118: warning: (361) function declared implicit int...

make[2]: *** [dist/default/production/24tst.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
:0: error: (499) undefined symbol:
_initialise(dist/default/production\24tst.X.production.obj)
(908) exit status = 1
nbproject/Makefile-default.mk:131: recipe for target 'dist/default/production/24tst.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/kees/MPLABXProjects/24tst.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/kees/MPLABXProjects/24tst.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 8s)


wellicht weet iemand waar dit aan ligt

  • vincent87
  • Registratie: Februari 2023
  • Laatst online: 29-03 13:36
het lijkt in het commando initialise te zitten als ik deze weghaal werkt het wel
Pagina: 1


Tweakers maakt gebruik van cookies

Tweakers plaatst functionele en analytische cookies voor het functioneren van de website en het verbeteren van de website-ervaring. Deze cookies zijn noodzakelijk. Om op Tweakers relevantere advertenties te tonen en om ingesloten content van derden te tonen (bijvoorbeeld video's), vragen we je toestemming. Via ingesloten content kunnen derde partijen diensten leveren en verbeteren, bezoekersstatistieken bijhouden, gepersonaliseerde content tonen, gerichte advertenties tonen en gebruikersprofielen opbouwen. Hiervoor worden apparaatgegevens, IP-adres, geolocatie en surfgedrag vastgelegd.

Meer informatie vind je in ons cookiebeleid.

Sluiten

Toestemming beheren

Hieronder kun je per doeleinde of partij toestemming geven of intrekken. Meer informatie vind je in ons cookiebeleid.

Functioneel en analytisch

Deze cookies zijn noodzakelijk voor het functioneren van de website en het verbeteren van de website-ervaring. Klik op het informatie-icoon voor meer informatie. Meer details

janee

    Relevantere advertenties

    Dit beperkt het aantal keer dat dezelfde advertentie getoond wordt (frequency capping) en maakt het mogelijk om binnen Tweakers contextuele advertenties te tonen op basis van pagina's die je hebt bezocht. Meer details

    Tweakers genereert een willekeurige unieke code als identifier. Deze data wordt niet gedeeld met adverteerders of andere derde partijen en je kunt niet buiten Tweakers gevolgd worden. Indien je bent ingelogd, wordt deze identifier gekoppeld aan je account. Indien je niet bent ingelogd, wordt deze identifier gekoppeld aan je sessie die maximaal 4 maanden actief blijft. Je kunt deze toestemming te allen tijde intrekken.

    Ingesloten content van derden

    Deze cookies kunnen door derde partijen geplaatst worden via ingesloten content. Klik op het informatie-icoon voor meer informatie over de verwerkingsdoeleinden. Meer details

    janee