Please dont take offence, but using an I2C is quite basic, and I think if you cant master that then you may be in trouble with the other parts of your project, I can supply some code for read/write to I2C if you like but they are in assembly and written for 16F series.I've tried to use a rtc,realized wasn't as easy as I thought
It would, although it seems a waste of the pics resources, not to mention an additional component.Then I thought of using a 555 timer to generate the interrupts every 2 seconds, will that be workable?
Yes, some PICS have onboard UART, others dont, but you can still do it in software without, my method is to use an 232 MAX IC and use software on the PIC, simply because I have heard rumours of problems with the PICs UART in some case. The software involved is very easy, as is the circuitry.Have the 555 timer on the main device,generating interrupts every 2 secs. The wirespeed will transmit as soon as it has calculated a wirespeed. Can the PIC buffer recieved UART bytes
The PIC will only "respond" to anything you tell it to, its up to you and your program what you do with anything on the I/O portsI'm not sure how the 18f452 will handle continuously recieved data and not reading it,when I'm ready to read the wirespeed the last recieved data would be ready for me
Thats fine as long as you are aware that whilst in an ISR then the main program will be "paused"The PIC will stay in the ISR for a relatively long time
I was thinking to use timer1 to wait for the 2 seconds to pass.When I'm doing other things,will timer1 still be still be timming the 2 seconds
rom char sp_units[10] = "mm/sec"; //The rom qualifier denotes that the object is
//located in program memory
rom char vol_units[10] = "Volts";
rom char cur_units[10] = "Amps";
rom char welcome[20] = "Welding Monitor";
rom char cursorL1[5] = "{A17" ;
rom char cursorL2[7] = "{C0202" ;
rom char cursorL5[7] = "{C0204";
rom char cursorL7[7] = "{C0206";
rom char cursorL9[9] = "{C0209";
rom int convFactor = (5.0 / 1024);
void main( )
{
//config RBO for interrupts
//OpenRB0INT( PORTB_CHANGE_INT_ON & PORTB_CHANGE_INT_ON & RISING_EDGE_INT & PORTB_PULLUPS_ON );
// configure external LCD
OpenXLCD( FOUR_BIT & LINES_5X7 );//four bit mode,multiple line display
OpenTimer0( TIMER_INT_ON & //interrupt on
T0_16BIT & //16bit mode
T0_SOURCE_INT & //internal clock source
T0_PS_1_32 ); //1:32 prescale
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_OFF &
USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_BRGH_HIGH &
USART_CONT_RX,25);
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST &
ADC_8ANA_0REF,ADC_CH0 &
ADC_INT_OFF);
INTCONbits.GIE = 1;
while (1)
{
}
}
#pragma interrupt system //save=PRODH, PRODL,section( ".tmpdata" )
void system(void)
{
int current_adc;
int voltage_adc;
int voltage;
int current;
char speed[7];
char voltage_str[7];
char current_str[7];
//// char sp_units[10] = "mm/sec";
// char vol_units[10] = "Volts";
// char cur_units[10] = "Amps";
// char welcome[20] = "Welding Monitor";
// char cursorL1[5] = "{A17" ;
// char cursorL2[7] = "{C0202" ;
// char cursorL5[7] = "{C0204";
// char cursorL7[7] = "{C0206";
// char cursorL9[9] = "{C0209";
INTCONbits.TMR0IE = 0;
SetChanADC(ADC_CH0); //select voltage channel
Delay10TCYx(3);
ConvertADC();
while( BusyADC());
voltage_adc=ReadADC();
voltage = (voltage_adc * convFactor *100);
SetChanADC( ADC_CH1 );//select current channel
Delay10TCYx(3);
ConvertADC();
while( BusyADC());
current_adc=ReadADC();
current = (current_adc *1.2* convFactor *600);
while(!DataRdyUSART());
getsUSART(speed , 7);//obtain speed
while (BusyUSART()); //TEST TO SEE IF CAN REMOVE
/***************write to LCD*******************/
while(BusyXLCD());
SetDDRamAddr(0x00);
putrsXLCD( clear );
while(BusyXLCD());
SetDDRamAddr(0x40);
putrsXLCD( clear );
while(BusyXLCD());
SetDDRamAddr(0x10);
putrsXLCD( clear );
while(BusyXLCD());
SetDDRamAddr(0x1C);
while(BusyXLCD());
putrsXLCD( sp_units );
while(BusyXLCD());
SetDDRamAddr(0x14);
while(BusyXLCD());
putsXLCD(speed);
while(BusyXLCD());
SetDDRamAddr(0x48);
while(BusyXLCD());
putrsXLCD( cur_units );
while(BusyXLCD());
SetDDRamAddr(0x40);
itoa(current,current_str);
while(BusyXLCD());
putsXLCD(current_str);
while(BusyXLCD());
SetDDRamAddr(0x08);
while(BusyXLCD());
putrsXLCD( vol_units );
while(BusyXLCD());
SetDDRamAddr(0x00);
itoa(voltage,voltage_str);
while(BusyXLCD());
putsXLCD(voltage_str);
/************write to tv screen*************************/
while (BusyUSART());
putrsUSART(cursorL1 ); //clear screen
while (BusyUSART());
putrsUSART( cursorL2 );
while (BusyUSART());
putrsUSART( welcome );
while (BusyUSART());
putrsUSART( cursorL5 );
while (BusyUSART());
putsUSART( speed );
while (BusyUSART());
putrsUSART( sp_units );
putrsUSART( cursorL7 );
while (BusyUSART());
putsUSART( current_str );
while (BusyUSART());
putrsUSART( cur_units );
while (BusyUSART());
putrsUSART( cursorL9 );
while (BusyUSART());
putsUSART( voltage_str );
while (BusyUSART());
putrsUSART( vol_units );
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?