-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTOS.c
More file actions
121 lines (77 loc) · 2.23 KB
/
RTOS.c
File metadata and controls
121 lines (77 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "lpc17xx.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_pwm.h"
#include "lpc17xx_adc.h"
#include "clcd.h"
#include "rtl.h"
__task void task1(void);
__task void my_ADC(void);
__task void my_LCD(void);
__task void my_PWM(void);
uint16_t ADC_BUF;
__task void task1 (void)
{
os_tsk_create(my_ADC ,1);
os_tsk_create(my_LCD ,2);
os_tsk_create(my_PWM ,3);
os_tsk_delete_self();
}
int main(){
os_sys_init(task1);
/*************************ADC*************************/
PINSEL_CFG_Type PinCfg;
PinCfg.Funcnum = 2;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 3;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
ADC_Init(LPC_ADC,100000);
ADC_ChannelCmd(LPC_ADC,ADC_CHANNEL_6,ENABLE);
/*************************LCD*************************/
lcd_clear();
lcd_puts("Salam");
/*************************PWM*************************/
PWM_TIMERCFG_Type pwmTimCfg;
PWM_MATCHCFG_Type pwmMatch0;
PINSEL_CFG_Type pwmPinsel;
Delay_RIT_Init();
pwmTimCfg.PrescaleOption=PWM_TIMER_PRESCALE_TICKVAL;
pwmTimCfg.PrescaleValue=1;
PWM_Init(LPC_PWM1,PWM_MODE_TIMER,&pwmTimCfg);
pwmMatch0.IntOnMatch=DISABLE;
pwmMatch0.MatchChannel=0;
pwmMatch0.ResetOnMatch=ENABLE;
pwmMatch0.StopOnMatch=DISABLE;
PWM_ConfigMatch(LPC_PWM1,&pwmMatch0);
PWM_MatchUpdate(LPC_PWM1,0,100,PWM_MATCH_UPDATE_NOW);
PWM_ChannelCmd(LPC_PWM1,1,ENABLE);
PWM_ResetCounter(LPC_PWM1);
PWM_CounterCmd(LPC_PWM1,ENABLE);
PWM_Cmd(LPC_PWM1,ENABLE);
pwmPinsel.Funcnum=PINSEL_FUNC_1;
pwmPinsel.OpenDrain=PINSEL_PINMODE_NORMAL;
pwmPinsel.Pinmode=PINSEL_PINMODE_TRISTATE;
pwmPinsel.Pinnum=0;
pwmPinsel.Portnum=2;
PINSEL_ConfigPin(&pwmPinsel);
return(0);
}
__task void my_ADC(void){
ADC_StartCmd(LPC_ADC,ADC_START_NOW);
while(!(ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_6,ADC_DATA_DONE))) {}
ADC_BUF = ADC_ChannelGetData(LPC_ADC,6);
}
__task void my_LCD(void){
while(1)
{
lcd_set_cursor(0,1);
lcd_printf("Temp is %u",&ADC_BUF);
Delay_RIT_ms(2500);
}
}
__task void my_PWM(void){
PWM_MatchUpdate(LPC_PWM1,1,100,PWM_MATCH_UPDATE_NOW);
Delay_RIT_ms(1000);
}