Hello friends, I need your help have time programming code for 8051 (c51) in keil and have no problem but now I would like to start with arm, specifically with LPC2138 and I want to convert the code I show is written for 8051 but not to start. All I know is how to define ports and little else. I swear I've tried but have not succeeded. the code is for a led matrix display and Works fine please can help me? thank you very much carlos
//crystal is 22-24MHz //was made for Keil compiler
#include <reg51.h> #define BAUDRATE 9600 sbit Cclock=P1^1; sbit Clatch=P1^0; sbit Cdata=P3^7; sbit Row1=P1^2; sbit Row2=P1^3; sbit Row3=P1^4; sbit Row4=P1^5; sbit Row5=P1^6; sbit Row6=P1^7; sbit Row7=P3^2; sbit Row8=P3^3;
unsigned int shift_delay;
unsigned char code font[96][16] = {
{0x00, 0x1f, 0x11, 0x11, 0x00}, // {0x10, 0x08, 0x04, 0x02, 0x01}, // {0x00, 0x11, 0x11, 0x1f, 0x00}, // {0x04, 0x08, 0x10, 0x08, 0x04}, // {0x01, 0x01, 0x01, 0x01, 0x01}, // {0x00, 0x00, 0x10, 0x08, 0x00}, // {0x12, 0x15, 0x15, 0x15, 0x0f}, //a {0x1f, 0x09, 0x09, 0x09, 0x06}, //b {0x0e, 0x11, 0x11, 0x11, 0x0a}, //c {0x06, 0x09, 0x09, 0x09, 0x1f}, //d {0x0e, 0x15, 0x15, 0x15, 0x0d}, //e {0x0f, 0x14, 0x14, 0x10, 0x10}, //f {0x09, 0x15, 0x15, 0x15, 0x0e}, //g {0x1f, 0x08, 0x08, 0x08, 0x07}, //h {0x00, 0x00, 0x17, 0x00, 0x00}, //i {0x01, 0x01, 0x01, 0x01, 0x1e}, //j {0x1f, 0x04, 0x04, 0x0a, 0x11}, //k {0x1e, 0x01, 0x01, 0x01, 0x01}, //l {0x0f, 0x10, 0x0f, 0x10, 0x0f}, //m {0x1f, 0x10, 0x10, 0x10, 0x0f}, //n {0x0e, 0x11, 0x11, 0x11, 0x0e}, //o {0x1f, 0x12, 0x12, 0x12, 0x0c}, //p {0x0c, 0x12, 0x12, 0x12, 0x1f}, //q {0x1f, 0x08, 0x10, 0x10, 0x08}, //r {0x09, 0x15, 0x15, 0x15, 0x12}, //s {0x1e, 0x09, 0x09, 0x01, 0x02}, //t {0x1e, 0x01, 0x01, 0x02, 0x1f}, //u {0x18, 0x06, 0x01, 0x06, 0x18}, //v {0x1e, 0x01, 0x1e, 0x01, 0x1e}, //w {0x1b, 0x04, 0x04, 0x04, 0x1b}, //x {0x19, 0x05, 0x05, 0x05, 0x1e}, //y {0x11, 0x13, 0x15, 0x19, 0x11}, //z {0x00, 0x04, 0x0e, 0x11, 0x00}, // {0x00, 0x00, 0x1f, 0x00, 0x00}, // {0x00, 0x11, 0x0e, 0x04, 0x00}, // {0x08, 0x10, 0x08, 0x04, 0x08}, // {0x00, 0x00, 0x00, 0x00, 0x00} // }; unsigned char column[41]= { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; //display memory, cleared before used.
void delayms(unsigned int ms) //just about 1ms { unsigned int n; unsigned int i; for (n=0; n<ms; n++) { for (i=0; i<200; i++); } }
void init_timer(void)//config timer for 6.7ms { TMOD=0x01; TH0=0xf8; TL0=0x00; TR0=1; ET0=1; EA=1; }
void Timer0 (void) interrupt 1 //using 2 { unsigned int index; unsigned int i,tmp1; unsigned char code rowtable[]={0,1,2,4,8,16,32,64,128}; TH0=0xf8; TL0=0x00; ET0=0; Row8=1; Row7=1; Row6=1; Row5=1; Row4=1; Row3=1; Row2=1; Row1=1; index++; if (index>8) index=1;
//column tmp1=rowtable[index]; for (i=1; i<41; i++) { Cdata=!(column[i] & tmp1); Cclock=0; Cclock=1; } //row Clatch=0; Clatch=1; switch (index) { case 1: Row1=0; break; case 2: Row2=0; break; case 3: Row3=0; break; case 4: Row4=0; break; case 5: Row5=0; break; case 6: Row6=0; break; case 7: Row7=0; break; case 8: Row8=0; break;
} ET0=1; }
void LED_put_byte(unsigned int inp) { unsigned char i; for (i=1;i<41;i++) column[i]=column[i+1]; column[40]=inp; }
void LED_puts(unsigned char *lcd_string) { unsigned char i,tmp_chr; while (*lcd_string) { tmp_chr=*lcd_string; for (i=0;i<6;i++) { LED_put_byte(font[tmp_chr-32][i]); delayms(shift_delay); } LED_put_byte(0); //space between character delayms(shift_delay); lcd_string++; } }
void main() { unsigned char m[40], i; TMOD=0x20; // Timer 1, mode-2 (8-bit auto reload) TH1=0xFA; //9600 baud rate SCON=0x50; TR1=1; //start timer 1
/* read 10 bytes or till enter key */ for (i = 0; i < 240; i++) { while (RI == 0); //wait to receive data if (SBUF == '\r') break; m[i] = SBUF; // save value of data RI = 0;
} m[i] = '\0';
init_timer(); shift_delay=40; //bigger = slower shift while(1) {
// display m LED_puts(m); } }
dear friend you are right but the examples I've seen more I get confused and lose myself. I do not want hagais work but as to start or some idea. with timer and uart thanks
Take an example that uses some I/O pins and an UART.
Read the code. Read the user manual for the I/O pins and the UART. Read the code. Read the user manual for the I/O pins and the UART.
Now you should be able to understand and "translate" the meaning of the I/O-related and UART-related code lines.
And you should have also picked up information from the user manual that the the processor can do even more things with the I/O pins and much more things with the UART. Things that are good to remember when you later need to solve more complex problems.
So switch to an existing example that uses a timer. Same there. Cross-correlate the use of timer registers with the user manual chapter about timers. Repeat two or three times. Then you should be able to understand how to initialize a timer. What values you can write to different registers, and what the result will be.
Jumping between the example code and the processor documentation is the only way you can learn. If I post source code, you will not understand that code any more than you understand all the already existing example programs. Understanding only comes from using the processor documentation as a wikipedia and look up exactly what different source lines is actually doing. And after a couple of iterations you will not only know what a line does, but also start to understand why it is needed.
When you do understand "what" and "why", then you have reached the level where you can take existing sample code and modify to solve a different problem. Which also means that you have reached the level where you can start with your own project and implement the individual sub-functions you require. With the sub-function implemented, the rest of the code doesn't care much what actual architecture you are using.
ok I'll try. I'll tell you my progress Thanks