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
/*
* 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
/*
* 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);
}
}
}