Pic låser sig selv
hej...vi sider og er ved at lave et styringsprogram og programet virker fint men vi har et problem med at det låser sig selv en gang i mellem nogen der kan finde en fejl...
programmet er til en pic16f874
M.V.H. rene kvist. her er koden:
#include <pic.h>
#include <string.h>
#include "C:\ht-pic\samples\delay.h"
#include <stdio.h>
#include "c:\ht-pic\samples\delay.c"
bank1 unsigned char text [20]; // Array for tekst on VFD diplay
int temp;
double temp1 ,temp2;
int ch0, ch1, ch2, ch3, ch5, ch6,ch7,ch8;
void lcd()
{
int i;
for (i=0; i<strlen(text); i++)
{
PORTB = text[i]; // Write a char to VFD
PORTC = 192;
PORTC = 0;
}
for (i=0; i<40-strlen(text); i++)
{
PORTB = 32; // Fill rest with space
PORTC = 192;
PORTC = 0;
}
}
void pulse(void)
{
int i;
RC2 = 1;
RC3 = 1; // Send pulse with width of "temp" lenght
for (i=1; i<temp; i++)
DelayUs(23); // 100 uS vith 3.2678 MHz crystal
RC2 = 0;
RC3 = 0;
}
void interrupt send(void) // Every 20 mS
{
temp = 5; // Startpulse of 0.5 mS lenght
pulse();
temp = 5 + (0.01953125 * ch0); // 10 / 512 = 0.01953125
pulse();
temp = 5 + (0.01953125 * ch1);
pulse();
temp = 5 + (0.01953125 * ch2);
pulse();
temp = 5 + (0.01953125 * ch3);
pulse();
if(ch5 > 523 && ch6 < 500)
{
temp = 10;
}
if(ch5 < 500 && ch6 < 500)
{
temp = 15;
}
if(ch5 < 500 && ch6 > 523)
{
temp = 20;
}
pulse();
if(ch7 > 523 && ch8 < 500)
{
temp = 10;
}
if(ch7 < 500 && ch8 < 500)
{
temp = 15;
}
if(ch7 < 500 && ch8 > 523)
{
temp = 20;
}
pulse();
T0IF = 0; // Clear Timer interrupt bit
}
void main(void)
{
DelayMs(20); // Wait for VFD is ready to recieve data
TRISA = 255; // Port A to input
TRISB = 0; // Port B to output
TRISC = 0; // Port C to output
RBIE = 0; // interrupt on change disabled
PEIE =0; // Pereferial interrupt disabled
GIE = 1; // global interrupt enable
ADCON0 = 129; // 00.000.0.0.1 - 2Tosc. Ch0. DONE, x, A/D-operating
ADCON1 = 128; // 1.000.0000 - MSB_of_adrh_0.xxx.All_to_analog
T0CS = 0; // Timer 0 increment on every instruction cycle
T0IE = 1; // Enable timer0 interrupt
PSA = 0; // Prescaler assigned to Timer 0
PS0 = 1;
PS1 = 1;
PS2 = 1; // Prescaler 1:64
T1CON = 1; // Enable Timer 1
PORTB = 56; // 8 Bit interface
PORTC = 128;
DelayMs(3);
PORTC = 0;
PORTB = 12; // Display on, Cursor off, Blink off
PORTC = 128;
DelayMs(3);
PORTC = 0;
PORTB = 1; // Clear display
PORTC = 128;
DelayMs(3);
PORTC = 0;
TMR1H = 0; // Reset 16 bit counter 1
TMR1L = 0;
TMR0 = 0; // Reset 8 bit counter 0
do {
sprintf(text, "Danfoss Universe");
lcd();
ADCON0 = 129; // Start A/D converter CH 0
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch0 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
ADCON0 = 137; // Start A/D converter CH 1
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch1 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
ADCON0 = 145; // Start A/D converter CH 2
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch2 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
ADCON0 = 153; // Start A/D converter CH 3
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch3 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
ADCON0 = 161; // Start A/D converter CH 5
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch5 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
ADCON0 = 169; // Start A/D converter CH 6
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch6 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
ADCON0 = 177; // Start A/D converter CH 7
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch7 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
ADCON0 = 185; // Start A/D converter CH 8
DelayUs(1);
ADGO = 1;
while(!ADIF);
DelayMs(1);
ch8 = (ADRESH * 256) + ADRESL; // convert the 16 bit to voltage-value 0-1023
temp1 = (5.0 / 1023.0) * ch5; // convert the 16 bit to voltage-value 0-5 Volt
temp2 = (5.0 / 1023.0) * ch6;
sprintf(text, "%2.2f %2.2f", temp1, temp2);
lcd();
} while(1);
}