Tool/software: Code Composer Studio
This code used to give a LCD upcount with a delay of 1 sec when I used the for loop multiplier as 80000. Now I have reduced it to 80 still it is providing the same amount of delay. No code is changed for clock.
With a delay loop of 80 it should provide a delay of 10us but it is providing now one sec delay. What could be the possibility of change in the speed.
#include <msp430F2616.h> #define DR P5OUT = P5OUT | BIT7 // define RS high #define CWR P5OUT = P5OUT & (~BIT7) // define RS low #define READ P5OUT = P5OUT | BIT5 // define Read signal R/W = 1 for reading #define WRITE P5OUT = P5OUT & (~BIT5) // define Write signal R/W = 0 for writing #define ENABLE_HIGH P5OUT = P5OUT | BIT6 // define Enable high signal #define ENABLE_LOW P5OUT = P5OUT & (~BIT6) // define Enable Low signal void check_busy(void); void data_read(void); void delay(unsigned int wt); void init(void); void init_lcd(void); void wr_lcd_cw(unsigned char lcd_cmd); void wr_lcd_dw(unsigned char wr_lcd_dw); void lcd_msg(unsigned char *ch); unsigned int a,b,c,d,e,f; //PIN R/W = /* * main.c */ unsigned char array[10]={"0123456789"}; int main(void) { volatile unsigned int i ; WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer init(); init_lcd(); //delay(500); wr_lcd_cw(0x80); lcd_msg(( unsigned char *)"UP count"); while (1) { for(a=0;a<10;a++) { wr_lcd_cw(0xC0); wr_lcd_dw(array[a]); for(b=0;b<10;b++) { wr_lcd_cw(0xC1); wr_lcd_dw(array[b]); for(c=0;c<10;c++) { wr_lcd_cw(0xc2); wr_lcd_dw(array[c]); for(d=0;d<10;d++) { wr_lcd_cw(0xc3); wr_lcd_dw(array[d]); P1OUT ^= BIT5|BIT6|BIT7; // Toggle P1.0 using exclusive-OR delay(1200); } } } } } } void delay(unsigned int wt) { unsigned int k; volatile unsigned int i ; for(k=0;k <= wt ;k++) { for( i = 0 ; i <= 80 ; i++ ); } } void lcd_msg(unsigned char *ch) { while(*ch !='\0') { wr_lcd_dw(*ch); ch++; } } void wr_lcd_cw(unsigned char lcd_cmd){ // check_busy(); P4OUT=lcd_cmd; CWR; WRITE; ENABLE_HIGH;//EN=1 delay(3); ENABLE_LOW;//EN=0 } void wr_lcd_dw(unsigned char lcd_data){ // check_busy(); P4OUT=lcd_data; DR; WRITE; ENABLE_HIGH;//EN=1 delay(3); ENABLE_LOW;//EN=0 } void init_lcd(void) { wr_lcd_cw(0x38);delay(10);//LCD in 8 bit mode wr_lcd_cw(0x0e);delay(10);//LCD in 8 bit mode wr_lcd_cw(0x06);delay(10);//LCD in 8 bit mode wr_lcd_cw(0x01);delay(10);//LCD in 8 bit mode //lcd_content(0x02);//return to home location } void init(void) { DCOCTL = 0x56; BCSCTL1 = 0xC7; BCSCTL2 = 0x00; BCSCTL3 = 0x20; P1SEL=0; P5SEL=0; P4SEL=0; P1DIR=0xff; P4DIR=0xff; P5DIR=0xff; P1DIR |= BIT5|BIT6; // Set P4 bits 5 and 6 to output direction P4DIR = 0XFF; // Set Port 4 as output P5DIR = 0XFF; // Set Port 5 as output P4OUT = 0X00; P5OUT = 0X00; } void check_busy(void) { P4DIR &= ~(BIT7); // make P2.3 as input data_read(); while((P4IN & BIT7)==1) { data_read(); } P4DIR |= BIT7; // make P2.3 as output } void data_read(void) { CWR; READ; ENABLE_LOW; delay(2); ENABLE_HIGH; }