Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
Thing is RB0,RB1,RB2 and RB3 are doing different things, and will always be changing state
interrupt: { if RB4 = high && timingarray does not have number=4 yet number=4; if RB5 = high && timingarray does not have number=5 yet number=5; if RB6 = high && timingarray does not have number=6 yet number=6; if RB7 = high && timingarray does not have number=7 yet number=7; timingarray[i]=number; i++; timingarray[i]=time_from_timer(); i++; }main loop: wait for sound if i=7 //array is full and all sensors recorded printf(the array);
void main(){ //set up TRISB and TMR1 unsigned int time4,time5,time6,time7; unsigned char state; state=0; while(1) { if(RB4==0) { if(state&1<<4==0) { time4 = TMR1H<<8 + TMR1L; state|=1<<4; } } if(RB5==0) { if(state&1<<5==0) { time5 = TMR1H<<8 + TMR1L; state|=1<<5; } } if(RB6==0) { if(state&1<<6==0) { time5 = TMR1H<<8 + TMR1L; state|=1<<6; } } if(RB7==0) { if(state&1<<7==0) { time5 = TMR1H<<8 + TMR1L; state|=1<<7; } } if(state==0b11110000) { //rs232(time4); .... state=0; } } }
static void interruptisr(void) // Here be interrupt function - the name is // unimportant.{ if(T0IF) { // timer interrupt TMR0 -= 250; // reload the timer - 250uS per interrupt T0IF = 0; // clear the interrupt flag if(relay_timer != 0) // is the relay timer running? relay_timer--; // decrement it if(relay_timer == 0) // if it has time out RELAY = 1; // turn the relay off PORTB ^= 0x40; // toggle a bit to say we're alive } if(INTF) { // did we see a button press? RELAY = 0; // turn the relay on relay_timer = 4000; // start the timer - 4000 ticks = 1 second INTF = 0; // clear the interrupt }}For the high-end devices, the vector address is specified e.g. the timer0interrupt is usually at location 0x10 (see the data sheet for vectoraddresses). Here's the example:void interrupt timer0_isr(void) @ 0x10
void interrupt isr(void){if(RBIE && RBIF){printf("7");RBIF = 0;}if(TMR1IF && TMR1IE){printf("F");TMR1IF = 0;}}
#include <pic.h>#include <stdio.h>#include "usart.h"/******************************************************************************************************************************** * Author: Ian Robinson * * Date Created: December 2006 * * Project: EG3001 Project1 : Ultrasonic 3D position location * * Project Synopsis: A project to show ultrasonic 3D position location over an RS-232 link using the principle of trilateration * ********************************************************************************************************************************/__CONFIG(BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO);#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))static bit LED0 @ PORTBIT(PORTB, 0);// B1 used for RX// B2 used for TXstatic bit LED3 @ PORTBIT(PORTB, 3);static bit RX1 @ PORTBIT(PORTB, 4); // RX1 (RB4) TOP RIGHTstatic bit RX2 @ PORTBIT(PORTB, 5); // RX2 (RB5) BOTTOM RIGHTstatic bit RX3 @ PORTBIT(PORTB, 6); // RX3 (RB6) TOP LEFT (SET AS INPUTS WHEN TIMER 1 FUNCTIONS)static bit RX4 @ PORTBIT(PORTB, 7); // RX4 (RB7) BOTTOM LEFT (SET AS INPUTS WHEN TIMER 1 FUNCTIONS)//TRISB4 =1; //Put RB4 into input mode//TRISB5 =1; //Put RB5 into input mode//TRISB6 =1; //Put RB6 into input mode//TRISB7 =1; //Put RB7 into input mode/***********************************************Variable Declaration************************************************************/unsigned int i,j; //for loop pauseunsigned int timerReading;unsigned int timerReadingRX1;unsigned int timerReadingRX2;unsigned int compare;unsigned int time4=0;unsigned int time5=0;unsigned int time6=0;unsigned int time7=0;/***********************************************Function Declaration************************************************************/void initialRecieve(void);void check1(void);void check2(void);/***********************************************Main Function*******************************************************************/void interrupt isr(void){if(RBIE && RBIF){// if(RB4==0)// {// time4 = (TMR1H << 8) + TMR1L;// }// if(RB5==0)// {// time5 = (TMR1H << 8) + TMR1L;// }// RBIF = 0;time4 = (TMR1H << 8) + TMR1L;time5 = (TMR1H << 8) + TMR1L;RBIF = 0;}if(TMR1IF && TMR1IE){// TMR1ON = 0; printf("RB4 is ",time4); printf("\n"); printf("RB5 is ",time5); printf("\n");// printf("%10u\n",time6);// printf("%10u\n",time7);// time4,time5,time6,time7 = 0;// timerReading = 0;// TMR1ON = 1; TMR1IF = 0;}}void main(void){ unsigned char input; INTCON=0; // purpose of disabling the interrupts. init_comms(); // set up the USART - settings defined in usart.h T1CON = 0b00001100; // Timer 1 control register set-up TMR1H = 0; // Clear high bit TMR1L = 0; // Clear low bit T1OSCEN = 0; // Disable Built-in oscillator between RB6 and RB7 GIE = 1; // enable global interrupts PEIE = 1; // enable peripheral interrupts TMR1IF = 0; // clear Timer 1 interrupt flag TMR1ON = 1; // start Timer 1 TMR1IE = 1; // enable Timer 1 interrupt RBIE = 1; // enable interrupt on change RBIF = 0; // clear interrupt on change flag timerReading = 0; compare = 0;/***********************************************While Loop*********************************************************************/ while(1){// initialRecieve(); // TMR1ON = 0; // timerReading = (TMR1H << 8) + TMR1L; // TMR1ON = 1; // printf("%10u\t",timerReading);// if(RB7 == 0)// {// //printf("%10u\t",timerReading);// printf("RB7");// } }}/***********************************************End of Main and While Loop**************************************************************/