 |
:: عضو ذهبي ::
تاريخ التسجيل: Apr 2009
الدولة: العراق/ كوردستان
المشاركات: 2,916
|
|
نشاط [ سعيد قادر ]
قوة السمعة:152
|
|
11-01-2015, 07:52 PM
المشاركة 1
|
|
السلام عليكم
هذا الكود كتبه احد الاخوة وهو كود عداد يعد النبضات القادمة من مولد النبضات فى برنامج بروتس وسوالى هو ماذا اضيف فى الكود لكى اجعلة frequency meter اى يقرء التردد ؟؟
وشكرا لكم
الكود
كود:
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
unsigned short Overflow_Number=0; //stores timer0 overflow numbers
unsigned int counter=0; //stores counter value
char counter_txt[11]; //stores counter value converted to string
//initiallizations
void _init()
{
//initiallize LCD
lcd_init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
//pin B0 (LED) as output
trisb.b0=0;
portb.b0=0;
trisa.b4 = 1; // pin A4(T0CKI) as input
//OPTION_REG REGISTER
OPTION_REG.T0CS = 1; //Transition on RA4/T0CKI pin
OPTION_REG.T0SE = 1; //Increment on high-to-low transition on RA4/T0CKI pin
//INTCON REGISTER
intcon.b5=1; //timer0 overflow interrupt
intcon.b6=1; //Enables all unmasked peripheral interrupts
intcon.b7=1; //enable global interrupt
tmr0=0; //timer0 initial value
}
//ISR
void interrupt()
{
if(intcon.b2==1) //if timer0 is overlfowed
{
intcon.b2=0; //reset timer0 interrrupt flag
Overflow_Number++; //icrement every timer0 overflow(256)
if(Overflow_Number==255)
{
portb.b0 = 1;
}
}
}
void main()
{
_init(); //initiallizations
for(;;)
{
counter = ( Overflow_Number * 256 ) + tmr0; //get counter value from timer0
WordToStr(counter, counter_txt); //convert counter value to string
lcd_out(2,1, counter_txt); //display counter value
}
}
[IMG]  [/IMG]
الملفات
تــــــــــحميل
|