Vous êtes sur la page 1sur 4

Q1-A)

Max232 covert from Microcontroller voltage level to Pc voltage level


logic one in pic =5 volt but in pc is less than -3volt
logic zero in pic =0 volt but in pc is larger than 3 volt
-----------------------------------------------------------------------------------------------------------------------------

Q1-B)
Baud rate = (fosc)/4*16(x-1) - if BRGG=0 low baud rate
9600 = 4*10^6/4*16 (x-1)
so X= SPREG = 8
Baud rate = (fosc)/4*4(x-1) - if BRGG=1 highbaud rate
9600 = 4*10^6/4*4 (x-1)
so X= SPREG =28

when we use low baud rate error is equal .5 but when we use high the error ~= .01
-----------------------------------------------------------------------------------------------------------------------------

Q1-c)
1- Load the TBLPTR with Address
2- Using TBLWR instruct
3- Set EECON1 WREN=1 & EEPGD=1
4- Disable Interrupted GIE=0
5- EECON2= 0x55
6- EECON2= 0xAA
7- Wr =1
8- Start writing
9- Re -enable Interrupted GIE =1

-----------------------------------------------------------------------------------------------------------------------------

Q1_d)// using the Library of (EEPROM & UART!)


Unsigned short a[30];
void main(){
Uart1_init(9600);
for(int i =0 ; I < 30 ; i++){
a[i] = EEPROM_read(i)
uart_write(a[i])}}
Q2_a)

Compare Capture
Timer used 1 and 3 1 and 3
use Compare between the value Capture signal from the
stored in CCPR1H outside and stored it’s
or CCPR1L with timer Time of this signal on
and take if it’s equaled CCPR1H & CCPR1L
Reg used CCP1CON CCP1CON
CCP1H CCP1H
CCP1L CCP1L

Q2-b)
PR2= (Fosc / 4 *n * Fpwm ) – 1 = 85 -> n= 16
CCPR1L = .25 * 85 = 21 // duty cycle
DC1B2 : DC!B1 = 0 : 1

Q2-c)
Void main(){
PWM1_init(5000); // pwm init with freq = 5k
ADC_init();
while(1){
Int result = ADC_read (0);// 15K mean 1023 so we will map like this
if (result < =204){
Pwm1_Stop();
Pwm1_set_duty(51); // 100% is equal 255 so 20% is equal 51
pwm1_start() ;}
else if (result < =409){
Pwm1_Stop();
Pwm1_set_duty(102);
pwm1_start() ;}
else if (result < =613){
Pwm1_Stop();
Pwm1_set_duty(153);
pwm1_start() ;}
else if (result <= 818){
Pwm1_Stop();
Pwm1_set_duty(204);
pwm1_start() ;}
else if (result <= 1023){
Pwm1_Stop();
Pwm1_set_duty(255);
pwm1_start() ;}}}
Q3-a)
Q3-b)

1- Make CE=1
2- 8 bit address is shifted one bit at time
3- the bit number 7  A7 = 0
5- Read the Data
-----------------------------------------------------------------------------------------------------------------------------

Q3-c)
unsigned char spi ( unsigned char by){
SSPBUF= by;
WHILE(!SSPSTAT.BF );
RETURN SSPBUF;}
/////////////////////////////
void main(){
Trisc =0x10; // config i/p and o/p
SSPSTAT =0;
SSPCON1 = 0X22; // config the spi
PORTC.B2 = 1; // enable CE
spi(0x8f); //address of control Reg
spi(0x00); // enable write
PORTC.B2 = 0; // disable the spi to restart again
delay_ms(1);
PORTC.B2 = 1;
spi(0x80); // address for writing
spi(0x35); // seconds
spi(0x45); // Min
spi(0x51);}}}// hours it’s 12 hours and it Am so it’s equal = 01010001 = 0x51

Vous aimerez peut-être aussi