/Users/farahman/MPLABXProjects/MyFrist_C_Project.X/c_main.c |
1 /**********************************
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "xc.h"
20 #include "stdio.h"
21 #include "math.h"
22 #include "time.h"
23
24 #include <xc.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27
28
29
30
31 #pragma config FOSC = HS, FCMEN = OFF, IESO = OFF
32 #pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30
33 #pragma config WDTEN = ON, WDTPS = 2048
34 #pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC
35 #pragma config STVREN = ON, LVP = OFF, XINST = OFF
36 #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
37 #pragma config CPB = OFF, CPD = OFF
38 #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
39 #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
40 #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
41 #pragma config EBTRB = OFF
42
43
44
45 #define _XTAL_FREQ 8000000
46
47
48
49
50 void main (void)
51 {
52 int counter;
53 char counter2;
54 srand(1);
55 counter = 1;
56 TRISD = 0;
57
58 while(counter <= 15)
59 {
60 PORTD = counter;
61 counter++;
62 PORTD = rand();
63 counter = counter*2;
64 printf("random %d \n", counter);
65 __delay_ms(1000);
66 }
67 }
68
69
70
71
72
73
74 void main(void)
75 {
76 INTCON2bits.RBPU = 0;
77 ADCON1= 0x7F;
78 WPUBbits.WPUB0 = 1;
79 ANSELH = 0x00;
80 counter = 1;
81 TRISB = 0;
82
83 while(counter <= 15)
84 {
85 PORTB = counter;
86 counter++;
87 __delay_ms(1000);
88 }
89 }
90
91
92 --- setting port D
93 int counter;
94 void main(void)
95 {
96
97 counter = 1;
98 TRISD = 0;
99
100 while(counter <= 15)
101 {
102 PORTD = counter;
103 counter++;
104 __delay_ms(1000);
105 }
106 }
107
108
109
110 int main()
111 {
112 TRISB0 = 0;
113
114 while(1)
115 {
116 RB0 = 1;
117 __delay_ms(1000);
118 RB0 = 0;
119 __delay_ms(1000);
120 }
121
122 return 0;
123 }
124
125
126
127
128
129 unsigned char seg_code[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
130
131
132 void main()
133 {
134 TRISD = 0x00;
135 for (int i = 0; i<10; i++)
136 {
137 PORTD = seg_code[i];
138 __delay_ms(500);
139 }
140 }
141
142
143
144
145 void main (void) @0x100
146 {
147 while(1){
148 TRISD = 0x00;
149 TRISC = 0xFF;
150 TRISE = 0xFF;
151
152 asm("MOVLW 0x1F");
153 asm("ANDWF ANSEL");
154
155 asm("MOVLW 0xFF");
156 asm("MOVWF PORTD");
157 asm("MOVLW 0x0");
158 asm("MOVWF PORTD");
159 asm("MOVLW 0xFF");
160 if (PORTEbits.RE0 ==1 ){
161 asm("MOVLW 0xA");
162 asm("MOVWF PORTD");
163 }
164 }
165
166
167
168 ADCON1 = 0x0F;
169 TRISB = 0x24;
170
171 PORTB = 0x00;
172 INTCON2bits.RBPU = 1;
173 RCONbits.IPEN = 1;
174 INTCON2bits.INTEDG2 = 1;
175 INTCON3bits.INT2IP = 0;
176 INTCON3bits.INT2IE = 1;
177 INTCONbits.GIEH = 1;
178 INTCONbits.GIEL = 1;
179 while( 1 )
180 {
181 ClrWdt();
182 if ( PORTBbits.RB5 == 0 )
183 PORTBbits.RB4 = 0;
184 }
185 }
186