Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * startup.c
- *
- */
- #include <stdio.h>
- #define STK_CTRL ((volatile unsigned int *)(0xE000E010))
- #define STK_LOAD ((volatile unsigned int *)(0xE000E014))
- // Bargraph
- #define STK_VAL ((volatile unsigned int *)(0xE000E018))
- #define PORT_BARGRAPH_BASE 0x40021000 /* MD407 port E */
- #define portBargraphModer ((volatile unsigned int *) (PORT_BARGRAPH_BASE))
- #define portBargraphOtyper ((volatile unsigned short *) (PORT_BARGRAPH_BASE+0x4))
- #define portBargraphOspeedr ((volatile unsigned int *) (PORT_BARGRAPH_BASE+0x8))
- #define portBargraphOdrLow ((volatile unsigned char *) (PORT_BARGRAPH_BASE+0x14))
- // Display
- #define PORT_DISPLAY_BASE 0x40021000 /* MD407 port E */
- #define portModer ((volatile unsigned int *) (PORT_DISPLAY_BASE))
- #define portOtyper ((volatile unsigned short *)(PORT_DISPLAY_BASE+0x4))
- #define portOspeedr ((volatile unsigned int *) (PORT_DISPLAY_BASE+0x8))
- #define portPupdr ((volatile unsigned int *)(PORT_DISPLAY_BASE+0xC))
- #define portIdr ((volatile unsigned short *)(PORT_DISPLAY_BASE+0x10))
- #define portIdrLow ((volatile unsigned char *)(PORT_DISPLAY_BASE+0x10))
- #define portIdrHigh ((volatile unsigned char *)(PORT_DISPLAY_BASE+0x10+1))
- #define portOdrLow ((volatile unsigned char *)(PORT_DISPLAY_BASE+0x14))
- #define portOdrHigh ((volatile unsigned char *)(PORT_DISPLAY_BASE+0x14+1))
- #define B_E 0x40 /* enable */
- #define B_SELECT 4 /* välj ascii/lcd */
- #define B_RW 2 /* read/write */
- #define B_RS 1 /* register select */
- #define SIMULATOR
- void startup(void) __attribute__((naked)) __attribute__((section (".start_section")) );
- void startup ( void )
- {
- __asm volatile(
- " LDR R0,=0x2001C000\n" /* set stack */
- " MOV SP,R0\n"
- " BL main\n" /* call main */
- "_exit: B .\n" /* never return */
- ) ;
- }
- void app_init(void){
- * ((unsigned int *) 0x40021000) = 0x55555555;
- //* ((unsigned int *) 0x40021000) |= 0x55005555;
- }
- void delay_250ns (void){
- /* SystemCoreClock = 168000000 */
- *STK_CTRL = 0;
- *STK_LOAD = ( (168/4) -1 );
- *STK_VAL = 0;
- *STK_CTRL = 5;
- while( (*STK_CTRL & 0x10000 )== 0 ){
- }
- *STK_CTRL = 0;
- }
- void delay_mikro (unsigned int us){
- while( us-- ){
- delay_250ns();
- delay_250ns();
- delay_250ns();
- delay_250ns();
- }
- }
- void delay_milli( unsigned int ms ){
- #ifdef SIMULATOR
- while( ms-- )
- delay_mikro(1);
- #else
- while( ms-- )
- delay_mikro(1000);
- #endif
- }
- /*void main(void){
- app_init();
- while(1){
- *portBargraphOdrLow = 0;
- delay_milli(500);
- *portBargraphOdrLow = 0xFF;
- delay_milli(500);
- }
- }*/
- void ascii_ctrl_bit_set( unsigned char x ){
- unsigned char c;
- c = *portOdrLow;
- c |= ( B_SELECT | x );
- *portOdrLow = c;
- }
- void ascii_ctrl_bit_clear( unsigned char x ){
- unsigned char c;
- c = *portOdrLow;
- c &= ( B_SELECT | ~x );
- *portOdrLow = c;
- }
- void ascii_write_controller(unsigned char byte){
- ascii_ctrl_bit_set(B_E);
- *portOdrHigh = byte;
- delay_250ns();
- ascii_ctrl_bit_clear(B_E);
- }
- unsigned char ascii_read_controller(void){
- ascii_ctrl_bit_set(B_E);
- delay_250ns();
- delay_250ns();
- unsigned char rv = *portIdrHigh;
- ascii_ctrl_bit_clear(B_E);
- return rv;
- }
- void ascii_write_cmd (unsigned char command){
- ascii_ctrl_bit_clear(B_RS);
- ascii_ctrl_bit_clear(B_RW);
- ascii_write_controller(command);
- }
- void ascii_write_data (unsigned char data){
- ascii_ctrl_bit_set(B_RS);
- ascii_ctrl_bit_clear(B_RW);
- ascii_write_controller(data);
- }
- unsigned char ascii_read_status (void){
- * ((unsigned int *) 0x40021000) = 0x00005555;
- ascii_ctrl_bit_clear(B_RS);
- ascii_ctrl_bit_set(B_RW);
- unsigned char rv = ascii_read_controller();
- * ((unsigned int *) 0x40021000) |= 0x55550000;
- return rv;
- }
- unsigned char ascii_read_data (void){
- * ((unsigned int *) 0x40021000) = 0x00005555;
- ascii_ctrl_bit_set(B_RS);
- ascii_ctrl_bit_set(B_RW);
- unsigned char rv = ascii_read_controller();
- * ((unsigned int *) 0x40021000) |= 0x55550000;
- return rv;
- }
- void ascii_command(unsigned char command){
- while((ascii_read_status() & 0x80) == 0x80){}
- delay_mikro(8);
- ascii_write_cmd(command);
- delay_milli(2);
- }/*
- if (command & 0x01 || command & 0x02){
- delay_mikro(2);
- }
- else{//(command & 0x04 || command & 0x08 || command & 0x30 || command & 0x80)
- //delay_mikro(40);
- else if (command & 0x80 && )
- }*/
- void ascii_init(void){
- ascii_command(0x38);
- ascii_command(0x0C);
- ascii_command(0x01);
- ascii_command(0x06);
- }
- void ascii_write_char(unsigned char c){
- while((ascii_read_status() & 0x80) == 0x80){}
- delay_mikro(8);
- ascii_write_data(c);
- delay_milli(2);
- }
- /*
- void gotoxy(unsigned char row, unsigned row column){
- unsigned char adress;
- where(row=20;row>0;row--){
- adress = row-1
- if(column==2){
- adress = adress + 0x40;
- }
- }
- }
- */
- void ascii_gotoxy( unsigned char x, unsigned char y) {
- unsigned char address;
- if(y!=1){
- address=0x40 | (x-1);
- }
- else{
- address=(x-1);
- }
- ascii_write_cmd( 0x80 | address);
- delay_mikro(45);
- }
- int main(int argc, char **argv){
- char *s;
- char test1[] = "Alfanumerisk ";
- char test2[] = "Display - test";
- app_init();
- ascii_init();
- ascii_gotoxy(1,1);
- s = test1;
- while(*s)
- ascii_write_char(*s++);
- ascii_gotoxy(1,2);
- s = test2;
- while(*s)
- ascii_write_char(*s++);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement