Barun Sarkar
Newbie level 5

hi have used the code in proteus simulator and it works just fine but when i apply it the microprocessor does not give any out put. even the lcd does not display anything. please help.
View attachment pwm.txt
View attachment pwm.txt
Code C - [expand] 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 #include<pic.h> #include<math.h> #include"lcd.h" #include"delay.h" #include<stdio.h> #define PWM_Freq 1 //1Khz PWM frequency #define TMR2_PRE 16 //Timer2 Prescale void main() // main program begins { lcd_init(); unsigned x,y,c=0x100,z; float p,tmpr,f; int j; char a[5]; ADCON0=0; //ADC channel-1 (AN0) is selected,A/D clock=Fosc/4 TRISA=1; ADCON1=0xCE; //RA0 configured as ananlog (AN0),A/D result Right justified,A/D clock=Fosc/4 ADCON0=ADCON0|1; //ADC is turned on TRISC2=0; //PWM channel 1 and 2 configured as output TRISC1=0; PORTC = 0x00; CCP1CON=0x0c; //CCP1 and CCP2 are configured for PWM CCP2CON=0x0c; PR2=255; //Move the PR2 value T2CON=0x03; //Timer2 Prescale is 16 TMR2=0x00; TMR2ON=1; //Turn ON timer2 CCPR1L=0; lcd_gotol1(0);DelayMs(300); lcd_puts(" ");DelayMs(300); lcd_puts("T");DelayMs(300); lcd_puts("E");DelayMs(300); lcd_puts("M");DelayMs(300); lcd_puts("P");DelayMs(300); lcd_puts(" ");DelayMs(300); lcd_puts("B");DelayMs(300); lcd_puts("A");DelayMs(300); lcd_puts("S");DelayMs(300); lcd_puts("E");DelayMs(300); lcd_puts("D");DelayMs(300); lcd_puts(" ");DelayMs(300); lcd_puts("F");DelayMs(300); lcd_puts("A");DelayMs(300); lcd_puts("N");DelayMs(300); lcd_gotol2(0);DelayMs(300); lcd_puts("S");DelayMs(300); lcd_puts("P");DelayMs(300); lcd_puts("E");DelayMs(300); lcd_puts("E");DelayMs(300); lcd_puts("D");DelayMs(300); lcd_puts(" ");DelayMs(300); lcd_puts("R");DelayMs(300); lcd_puts("E");DelayMs(300); lcd_puts("G");DelayMs(300); lcd_puts("U");DelayMs(300); lcd_puts("L");DelayMs(300); lcd_puts("A");DelayMs(300); lcd_puts("T");DelayMs(300); lcd_puts("I");DelayMs(300); lcd_puts("O");DelayMs(300); lcd_puts("N");DelayMs(1000); DelayMs(1000); lcd_clear(); while(1) //infinite loop { ADCON0=ADCON0|4; //A/D conversion begins while(1) { if(ADCON0==0x01) break; } //A/D conversion ends x=ADRESH; //ADC result higher 2 bits y=ADRESL; //ADC result lower 8 bits PIR1=PIR1&~64; //ADC interrupt flag is cleared z=x*c+y; //combined 10 bit number formation f=z; //unsigned to float conversion p=(f*5)/1023; //equivalent voltage calculation from ADC output tmpr=p*100; //sensor output voltage to degree Celsius conversion j=floor(tmpr); sprintf(a,"Temp = %d °C",j); lcd_gotol1(0); lcd_puts(a); lcd_gotol2(0); if (tmpr<29) {CCPR1L=0; lcd_puts("Speed = 0% ");} else if(tmpr>=29 && tmpr<31) {CCPR1L=51; lcd_puts("Speed = 20% ");} else if(tmpr>=31 && tmpr<33) {CCPR1L=102; lcd_puts("Speed = 40% ");} else if(tmpr>=33 && tmpr<35) {CCPR1L=153; lcd_puts("Speed = 60% ");} else if(tmpr>=35 && tmpr<37) {CCPR1L=204; lcd_puts("Speed = 80% ");} else {CCPR1L=255; lcd_puts("Speed = 100%");} DelayMs(1000); } } //main program ends
Last edited by a moderator: