|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
|
Posted: Tue Nov 18, 2008 2:58 pm |
|
|
Hi ! I'm newcomer . May I have a question ?
My problem is "PWM resolutions".I don't know about it .
Would you please help me ?
Thanks very much! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
dientudong
Joined: 18 Nov 2008 Posts: 2
|
|
Posted: Wed Nov 19, 2008 2:49 am |
|
|
Code: | #include "E:\BAIBAOCAONHOM7\New Folder\taolao.c.h"
#include<16F877A.h>
unsigned char num[8]={0x00,0x15,0x21,0x31,0x48,0x50,0x64,0x78};
unsigned char j ;
void main()
{
set_tris_c(0);
while(1)
{
for(j=0;j<8;j++)
{
PORTC=num[j];
delay_ms(1);
}
}
} |
My problem is "error in PORTC". Would you please help me ?
Split thread into new topic.
-- Forum Moderator. |
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 19, 2008 5:24 am |
|
|
There is nothing called 'PORTC', unless you have declared it...
If you want to write a value to the port, the CCS function, is output_c(num[j]);
This has _nothing_ to do with PWM, which this thread is about.Why post your question here?... |
|
|
dientudong
Joined: 18 Nov 2008 Posts: 2
|
|
Posted: Wed Nov 19, 2008 8:20 am |
|
|
Code: | #include <16F877A.h> //
#use delay(clock=20000000) //
#include <lcd.c> //
float vantoc,soxung; //
int8 a,b,c,d,a1; //
int16 sovong,i; //
///////////////////////////////////////
////////////khai bao va chuong trinh ngat cho TIMER1/////////////////////
#int_TIMER1 //
void TIMER1_isr(void) //
{ //
soxung=get_timer0(); //get num pulses thatTimer0 counts //
set_timer1(65535); // Trong 1ms //
if(tmr1if==1) //if Timer1 overflows , tmr1if =1 //
{ //
intcon=0; //stop ngat (reset interrupt parameters ) //
a1=1; //cho a1=1 //
} //
} //
//////////////////////////end TIMER1///////////////////////////
//////////////////////////begin main program////////////////////////////
void main()
{
trisa=0xFF; //set RA4 input,pin get pulses from Encoder
trisb=0; //portC is output
trisc=0; // portC is output
trisd=0; // portD is output
lcd_init(); //ham khoi tao LCD
lcd_gotoxy(1,1); //row 1 column 1
lcd_putc("Beginning...."); // print beginning....
delay_ms(1000); // 1s
lcd_putc('\f'); //dotpoint flashs
setup_timer_2(T2_DIV_BY_2,254,1); //tao f(pwm)=9775Hz or T(pwm)=0.1023ms
setup_ccp1(CCP_PWM); //thiet lap chan CCP1 o che do PWM
for(i=0;i<1000;i++) //tu 0 den 1000 thi toc do tang dan
{
set_pwm1_duty(i); // Toc do tang dan
delay_ms(1);
set_timer0(0); //lam moi Timer0 de chuan bi dem xung
set_timer1(65535); //dat gia tri cho Timer1_khoang 1s
setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1); //cho phep ngat Timer1
enable_interrupts(GLOBAL); //cho phep ngat toan cuc
delay_ms(10); //
if(a1==1) //every Timer1 interrupts, a1=1 ,then calculate vantoc
{
vantoc=((float)(60*soxung)/(0.01*100)); //Tinh van toc
a=vantoc/1000; //chia lay phan nguyen
b=(int)(vantoc-1000*a)/100; //chia lay phan nguyen
c=(int)(vantoc-1000*a-100*b)/10; //chia lay phan nguyen
d=(int)vantoc%10; //chia lay phan du
///////////////////toi phan hien thi LCD/////////////////////////////
lcd_gotoxy(3,3); //den vi tri hang 3 cot 3
lcd_putc(a+48); //in ra a
lcd_gotoxy(3,4); //den vi tri hang 3 cot 4
lcd_putc(b+48); //in ra b
lcd_gotoxy(3,5); //den vi tri hang 3 cot 5
lcd_putc(c+48); //in ra c
lcd_gotoxy(3,6); //den vi tri hang 3 cot 6
lcd_putc(d+48); //in ra d
lcd_gotoxy(4,3); //den vi tri hang 4 cot 3
lcd_putc("vong/phut"); //in ra "vong/phut"
lcd_gotoxy(2,2); //den vi tri hang 2 cot 2
lcd_putc("toc do dc"); //in ra "toc do dc"
delay_ms(5); //
tmr0if=0;tmr1if=0; //Xoa co tran cua Timer0 va Timer1
}
}
} |
I have problem in the code. Please help me. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|