المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : مشروع pressure


mohammed khyrallah
11-02-2015, 09:06 PM
السلام عليكم ورحمه الله وبركاته
ارجو الافاده في مشروعي
lcd لا تكتب بشكل مستقر (يوجد رعشه بالقراءه)








sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB5_bit;
sbit LCD_D7 at RB6_bit;

sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB6_bit;

unsigned cnt;
int temp_res;
char temp[12];
char a,b ;
unsigned int rtemp=100;
char ntemp[10];
void interrupt() {

if (TMR0IF_bit) {
cnt++ ;
TMR0IF_bit = 0; // clear TMR0IF
TMR0 = 96;

if (cnt >=100) {

cnt=0;

temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
temp_res = (temp_res *1)/41;
IntToStr(temp_res,temp);


Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(2,9,"P="); // Write text in first row

Lcd_Out(2,1,"T="); // Write text in second row
Delay_ms(200);
IntToStr(rtemp,ntemp);Lcd_Out(2,3,ntemp);
IntToStr(temp_res,temp);lcd_out(2,11,temp) ;
Delay_ms(100);
if(portc.f0==1&&rtemp<15000){rtemp=rtemp+1000;;delay_ms(1000);}
if(portc.f1==1&&rtemp>100){rtemp=rtemp-1000;delay_ms(100);}
if(portb.f0==1){portc.f4=0;portc.f5=1;Lcd_Out(1,1,"MODE=DELTA_P");}
if(portb.f0==0){portc.f4=1;portc.f5=0;Lcd_Out(1,1,"MODE=TIMER__");}

} } }


void main() {
OPTION_REG = 0x84; // Assign prescaler to TMR0
CMCON=0X07;
TRISB.F0=1;
TRISC=0B00001111;
TRISD = 0; // PORTB is output
PORTD=0;
TMR0 = 96; // Timer0 initial value
INTCON = 0xA0; // Enable TMRO interrupt
cnt = 0;

do {
if(portb.f0==1){
if(temp_res>8){
portc.f6=1; delay_ms(100); portc.f6=0;vdelay_ms(rtemp);
portc.f7=1; delay_ms(100); portc.f7=0;vdelay_ms(rtemp);
portd=0b00000001;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00000010;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00000100;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00001000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00010000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00100000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b01000000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b10000000;delay_ms(100); portd=0;vdelay_ms(rtemp);
}
if(temp_res<8){portd=0;}
}
if(portb.f0==0){
portc.f6=1; delay_ms(100); portc.f6=0;vdelay_ms(rtemp);
portc.f7=1; delay_ms(100); portc.f7=0;vdelay_ms(rtemp);
portd=0b00000001;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00000010;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00000100;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00001000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00010000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b00100000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b01000000;delay_ms(100); portd=0;vdelay_ms(rtemp);
portd=0b10000000;delay_ms(100); portd=0;vdelay_ms(rtemp);

}

} while(0);
}