Hello again...
This weeks task: make your own board output something...
Let me short think about some output-ideas:
T1CON = 0b00000011; //Config Timer2
IPR1bits.TMR1IP = 1; //Setting Timer1 to high-prio
PIE1bits.TMR1IE = 0; //Disable Timer1 Interrupt until drive to middle
PIR1bits.TMR1IF = 0; //rest TMR1-Interrupt flag
RCONbits.IPEN = 1; //enable High/Low-Prio
ei(); // master switch to enable interrupt
INTCONbits.GIE_GIEH = 1; //enable all Low-Prio-Interrupts
INTCONbits.PEIE_GIEL = 1; //enable all Low-Prio-Interrupts
void interrupt trigger_interrupt(void) //High priority interrupts
{
if (PIR1bits.TMR1IF == 1)
{
if (motor_step == 1) {motor_step = 0;}
else
{
if (motor_direction == 0) {motor_direction = 1;}
else {motor_direction = 0;}
motor_step = 1;
}
TMR1H = high;
TMR1L = low;
PIR1bits.TMR1IF = 0;
}
}
void play(int frequency)
{
//Using Timer1 for PWM-Generating
//Timer is configuered as 16-Bit, running on FOSC/4 = 8MHz, 65536 counts max
//For one periode pf sound (1Hz) two timer-overflow are needed (one low, one high)
//TMR1H is the high register
//TMR1L is the low register
long temp;
if (frequency <=62) frequency = 62;
if (frequency <=62) frequency = 62;
temp = -((8000000/frequency/2)-65536);
high = temp / 255;
low = temp - (high * 255);
drive_enable = 0; //Switch drive on
}
void stop()
{
drive_enable = 1; //Switch drive off
}
PIE1bits.TMR1IE = 0; //Disable Timer1 Interrupt
//function to generate delays of ms without max limit
void sleep (int delay)
{
int i;
for(i=0; i<=delay; i++)
{
__delay_ms(1);
}
}
play(frequency);sleep(sometime);stop();sleep(sometime)