|
Tài trợ cho PIC Vietnam |
RTOS và Thuật toán với PIC RTOS và Các thuật toán dùng cho PIC/dsPIC/PIC32 Mod: phamminhtuan |
|
Ðiều Chỉnh | Xếp Bài |
19-01-2009, 09:19 PM | #1 |
Đệ tử 4 túi
Tham gia ngày: May 2007
Bài gửi: 65
: |
RTOS và ngắt khi giao tiếp rs232?
Chào mọi người.
Mình định viết chương trình giao tiếp máy tính dùng PIC6f877A và RTOS của CCS. Cho mình hỏi khi PIC nhận dữ liệu từ máy tính thì khi dùng RTOS ta phải làm sao để nhận được ký tự. Khi viết chương trình bình thường ta dùng #INT_RDA. Còn khi dùng RTOS thì phải làm sao? Mong mọi người giúp đỡ. Thanks nhiều. |
22-04-2009, 11:16 PM | #2 |
Nhập môn đệ tử
Tham gia ngày: Jun 2008
Bài gửi: 10
: |
Trong phần help của nó có cái này,vừa xài ngắt,vừa xài RTOS, ko biết đúng ý bác ko:
Code:
///////////////////////////////////////////////////////////////// /// This file demonstrates how to create a basic command /// /// line using the serial port withought having to stop /// /// RTOS operation, this can also be considered a /// /// semi kernal for the RTOS. /// /// /// /// this demo makes use of the PIC18F452 prototyping board /// ///////////////////////////////////////////////////////////////// #include <18F452.h> #use delay(clock=20000000) #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7) #use rtos(timer=0,minor_cycle=100ms) #define RED PIN_B5 #define GREEN PIN_A5 #include <string.h> // this character array will be used to take input from the prompt char input [ 30 ]; // this will hold the current position in the array int index; // this will signal to the kernal that input is ready to be processed int1 input_ready; // different commands char en1 [ ] = "enable1"; char en2 [ ] = "enable2"; char dis1 [ ] = "disable1"; char dis2 [ ] = "disable2"; #task(rate=1000ms,max=100ms) void The_first_rtos_task ( ); #task(rate=1000ms,max=100ms) void The_second_rtos_task ( ); #task(rate=500ms,max=100ms) void The_kernal ( ); // serial interupt #int_rda void serial_interrupt ( ) { if(index<29) { input [ index ] = getc ( ); // get the value in the serial recieve reg putc ( input [ index ] ); // display it on the screen if(input[index]==0x0d){ // if the input was enter putc('\n'); input [ index ] = '\0'; // add the null character input_ready=TRUE; // set the input read variable to true index=0; // and reset the index } else if (input[index]==0x08){ if ( index > 1 ) { putc(' '); putc(0x08); index-=2; } } index++; } else { putc ( '\n' ); putc ( '\r' ); input [ index ] = '\0'; index = 0; input_ready = TRUE; } } void The_first_rtos_task ( ) { output_low(RED); delay_ms(50); output_high(RED); } void The_second_rtos_task ( ) { output_low(GREEN); delay_ms(20); output_high(GREEN); } void The_kernal ( ) { while ( TRUE ) { printf ( "INPUT:> " ); while(!input_ready) rtos_yield ( ); printf ( "%S\n\r%S\n\r", input , en1 ); if ( !strcmp( input , en1 ) ) rtos_enable ( The_first_rtos_task ); else if ( !strcmp( input , en2 ) ) rtos_enable ( The_second_rtos_task ); else if ( !strcmp( input , dis1 ) ) rtos_disable ( The_first_rtos_task ); else if ( !strcmp ( input , dis2 ) ) rtos_disable ( The_second_rtos_task ); else printf ( "Error: unknown command\n\r" ); input_ready=FALSE; index=0; } } void main ( ) { // initialize input variables index=0; input_ready=FALSE; // initialize interrupts enable_interrupts(int_rda); enable_interrupts(global); rtos_run(); } |
03-01-2010, 02:49 AM | #3 |
Đệ tử 4 túi
Tham gia ngày: Mar 2009
Bài gửi: 64
: |
Đâu phải con vđk nào cũng dùng được RTOS đâu. Thường những con có nhiều flash, ram, thì mới chơi được. ví dụ mấy con atmega128 hoặc dspic33f ....
|
03-01-2010, 10:28 AM | #4 |
Nhập môn đệ tử
Tham gia ngày: Mar 2009
Bài gửi: 10
: |
em đang làm đồ án về từ điển tra chân IC,bác nào biết phần cứng nó gồm các khối nào thì giúp giùm.Cảm ơn nhiều.
|
|
|