السلام عليكم ورحمة الله وبركاته
انا طالب في أحد جامعات أمريكا وعندي دكتور يهودي من اصل بريطاني أمريكي الجنسية ومستقعد لكل العرب لو سمحتوا أفزعولي
....
المشكله أن الدكتور أعطاني سؤال ويريد حله يوم الأثنين وأنا اشتغل على البرنامج منذو اسبوع وما طلع معي نتيجه....
أنا ابرمج (chip microprosser 9S12's) .......
السؤال هو :
Write an ISR to measure the period of a waveform when IRQ is activated. show all code necessary to setup the ISR. The frequency of the waveform to be measured is between 1kHz and 5kHz. Use the greatest precision available. Include a very generous number of comments.
by the way, he gave us a program in class that might help to do it.... as he said.
that program is the following:
#include <stdio.h>
#define TIOS *(unsigned char volatile*)(0x0040)
#define DDRT *(unsigned char volatile*)(0x0242)
#define TSCR1 *(unsigned char volatile*)(0x0046)
#define TSCR2*(unsigned char volatile*)(0x004D)
#define TIE *(unsigned char volatile*)(0x004C)
#define TFLG1 *(unsigned char volatile*)(0x004E)
#define TCTL2 *(unsigned char volatile*)(0x0049)
#define TC3*(unsigned short volatile*)(0x0056)
#define TCNT *(unsigned short volatile*)(0x0044)
// setup of ISR
extern void TC3 handle (void); //prototype declaration for timer
#pragma abs_address:0x3E68 // RAM address. channel 3 ISR
void (* interrupt_vectors[ ])void={TC3 handler};
#pragma end_abs_address
unsigned int high,low; // accessible in ISR
int main()
{
high= 7200;// 300us
low=16800;//700us, duty cycle=0.3
asm("sei"); // i = 1, interrupts disabled.
TIOS|=0x08;// set OC3 to output compare,00001000
DDRT |=0x08;//PORT T bit 3 is an output.(not stricktly nessary, tios does this.
TSCR1 = 0x80;// enable timer no fast flag clears will not poll flags
TSCR2=0x00;// timer overflow interrupt - inhibited , prescaler bits 000.
TIE |= 0x08;// enable interrupt on channel 3 (IOC3).
TFLG1 =0x08;// clear C3F Flag by writing a '1' to that bit.
TCTL2 |= 0xC0;// set PT3 (IOC3) to be '1' on an output compare.
TC3=TCNT+50;// TC3 gives time of first rising edge event.
asm("cli"0;
while(1);// <-------- your program goes here
return 0;
}
#pragma interrupt_handler TC3 handler()
void TC3 handler()
{
TFLG1 = 0x08;//clear C3F flag.
if(TCTL2&0x40);// TCTL2 is either 1100 0000 go high
// 1000 0000 go low
// true if output use set to go to '1' on a successful compare
{
TC3=TC3+high;
TCTL2&=0xBF;//1011 1111 ----> go low
}
else
{
TC3=TC3+low;// time to stay low
TCTL2|=0x40;// TCTL2=11000000 high
}
}
please help your brother out guys
in case that you guys can not read the code there is an attached copy of it.
Sallam
والله في عون المسلم ما دام المسلم في عون أخيه