|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
data logger |
Posted: Wed Mar 22, 2006 9:06 am |
|
|
My current project involves a pic mcu based datalogger. So far the simple code initially detects a passing object and when high a count is incremented on a seven seg display. The code is as follows:-
/*************************************************************************************
SAQlab6: To make the 2-digit 7-segment display count
up from 00 through 99 when object passes sensor
*************************************************************************************/
#include <16f877.h>
#use delay(clock = 4000000) /* Tell compiler using a 4MHz crystal */
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP
#byte PORTD = 8 /* PortD is at File 8 */
#byte PORTA = 5 /* PORTA is at File 5 */
#bit DIGIT_L = PORTA.2 /* Least significant digit enabled by RA2/TR_Q2 */
#bit DIGIT_H = PORTA.3 /* Most significant digit enabled by RA3/TR_Q1 */
#bit SW_FIVE = PORTA.0 /* Set up porta.0 to SW_FIVE */
int const svn_seg[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
main()
{
int loop_count=0, left_digit, right_digit, number=0;
set_tris_d(0x00); /* Set port D to be outPuts */
set_tris_a(0xF3); /* Set PORTA bits 3 & 2 to be outputs */
setup_adc_ports(NO_ANALOGS); /* Make PortA all digital, no analog inPuts */
while(TRUE)
{
left_digit = number/10; /* The Tens digit */
right_digit = number%10; /* The remainder after div by ten is the Units digit */
if((loop_count & 1) == 1) /* Test if millisecond count odd or even; if even skip to the else*/
{
DIGIT_H=0; DIGIT_L=1; /* Switch left 7-seg display on and the other one off */
PORTD=svn_seg[left_digit];/* This picks up the nth value of the array of 7-segment codes */
}
else
{
DIGIT_H=1; DIGIT_L=0; /* Switch right 7-segment display on and the other one off */
PORTD=svn_seg[right_digit];
}
delay_ms(4); /* 4-ms delay */
if(SW_FIVE == 0) /* IF SW = 0 IE ON */
{
number++; /* Increment the main display count */
if (number == 100) number = 0;
delay_ms(4); /* Debounce */
while(SW_FIVE == 0) ; /* Wait until switch is released */
}
loop_count++;
} /* End of while loop */
} /* End of main() */
The next stage is to gather a real time in between the detection of each passing object. Timer 0 would probebly be the best option so i was thinking something along the lines of
#define INTS_PER_SECOND 76 //(20000000/(4*256*256))
byte seconds; //Number of interrupts left b4 1sec elapsed
#int _rtcc
clock_isr() {
if{--int_count==0) {
++seconds;
int_count=INTS_PER_SECOND;
}
}
main() {
byte start;
int _count=INTS_PER_SECOND;
set_rtcc(0);
setup_counters (RTCC_INTERNAL, RTCC_DIV_256);
enable_interrupts (INT_RTCC);
enable_interrupts (GLOBAL)
}
}
I was wondering if this could be implemented to the code i have written or would there be a simpler or easier method of doing so. |
|
|
wise up son Guest
|
data logger |
Posted: Wed Mar 22, 2006 9:36 am |
|
|
ill give u some code if i can get something back |
|
|
jonboy
Joined: 22 Mar 2006 Posts: 1
|
|
Posted: Thu Mar 23, 2006 5:59 am |
|
|
like wat? If i can..... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|